Dockerizing an Ionic Capacitor App: A Step-by-Step Multi-Arch Dockerfile Guide
Execute the image through podman or docker
podman buildx build --platform linux/amd64,linux/arm64 -t my-ionic-app:latest .
docker buildx build --platform linux/amd64,linux/arm64 -t my-ionic-app:latest .
Run the image
podman run -it --rm --privileged -v /dev/bus/usb:/dev/bus/usb my-ionic-app:latest bash
docker run -it --rm --privileged -v /dev/bus/usb:/dev/bus/usb my-ionic-app:latest bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Multi-Arch Ionic Capacitor Dockerfile | |
FROM node:20 AS build | |
# Maintainer Information | |
LABEL maintainer="Manikandan <manikandankasi@fss.co.in>" | |
# Define arguments for versions | |
ARG JAVA_VERSION=17 | |
ARG NODEJS_VERSION=20 | |
ARG ANDROID_SDK_VERSION=11076708 | |
ARG ANDROID_BUILD_TOOLS_VERSION=34.0.0 | |
ARG ANDROID_PLATFORMS_VERSION=34 | |
ARG GRADLE_VERSION=8.2.1 | |
ARG IONIC_VERSION=7.2.0 | |
ARG CAPACITOR_VERSION=6.0.0 | |
# Set up environment | |
ENV DEBIAN_FRONTEND=noninteractive | |
ENV LANG=en_US.UTF-8 | |
# Set working directory | |
WORKDIR /tmp | |
# Update and install dependencies | |
RUN apt-get update -q && apt-get install -qy \ | |
apt-utils \ | |
locales \ | |
gnupg2 \ | |
build-essential \ | |
curl \ | |
usbutils \ | |
git \ | |
unzip \ | |
p7zip-full \ | |
python3 \ | |
openjdk-${JAVA_VERSION}-jre \ | |
openjdk-${JAVA_VERSION}-jdk \ | |
android-tools-adb | |
# Set locale | |
RUN locale-gen en_US.UTF-8 && update-locale | |
# Install Gradle | |
ENV GRADLE_HOME=/opt/gradle | |
RUN mkdir -p $GRADLE_HOME \ | |
&& curl -sL https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip -o gradle.zip \ | |
&& unzip -d $GRADLE_HOME gradle.zip \ | |
&& rm gradle.zip | |
ENV PATH=$PATH:$GRADLE_HOME/gradle-${GRADLE_VERSION}/bin | |
# Install Android SDK tools | |
ENV ANDROID_HOME=/opt/android-sdk | |
RUN curl -sL https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_VERSION}_latest.zip -o cmd-tools.zip \ | |
&& unzip cmd-tools.zip -d /opt/android-sdk \ | |
&& rm cmd-tools.zip \ | |
&& yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME --licenses \ | |
&& $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME "platform-tools" "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" "platforms;android-${ANDROID_PLATFORMS_VERSION}" | |
ENV PATH=$PATH:$ANDROID_HOME/cmdline-tools:$ANDROID_HOME/platform-tools | |
# Install Node.js and NPM | |
RUN curl -sL https://deb.nodesource.com/setup_${NODEJS_VERSION}.x | bash - \ | |
&& apt-get update -q && apt-get install -qy nodejs | |
ENV NPM_CONFIG_PREFIX=${HOME}/.npm-global | |
ENV PATH=$PATH:${HOME}/.npm-global/bin | |
# Install Ionic and Capacitor CLI globally | |
RUN npm install -g @ionic/cli@${IONIC_VERSION} \ | |
&& npm install -g @capacitor/cli@${CAPACITOR_VERSION} | |
# Clean up | |
RUN apt-get autoremove -y \ | |
&& apt-get clean -y \ | |
&& rm -rf /var/lib/apt/lists/* /tmp/* | |
# Set project working directory | |
WORKDIR /workdir | |
COPY . . | |
# Install dependencies | |
RUN npm install | |
# Ensure Ionic CLI is installed | |
RUN npm install -g @ionic/cli | |
# Set OpenSSL legacy provider | |
ENV NODE_OPTIONS=--openssl-legacy-provider | |
# Navigate to Android folder and build the APK | |
WORKDIR /workdir/android | |
RUN ls -la # Debugging step | |
RUN ./gradlew assembleRelease --verbose | |
# Expose necessary ports | |
EXPOSE 8554 5555 | |
# Start the emulator (commented out if not needed) | |
# CMD ["emulator", "-avd", "Pixel_6_API_30", "-no-audio", "-no-boot-anim", "-gpu", "swiftshader_indirect", "-no-window"] |
Comments
Post a Comment