Crear un contenedor de Expo (EAS) con Docker para generar Build Android para React Native

Tiempo de lectura: 2 minutos

Reading time: 3 minutes

Hello, today we are going to see how we can create a Docker container that generates Android Builds (APKs) locally using React Native.

First, we are going to generate our docker-compose.yml file as follows:

version: "3.1"
services:

  react_native_dev:
    build: 
      context: ./Dockerfile
      dockerfile: react_native
    restart: unless-stopped
    container_name: react_native_dev
    environment:
      EXPO_CLI_NO_PROMPT: 1
      EXPO_TOKEN: "token_expo"
    volumes:
      - ./app_react:/app
    ports:
      - "3000:3000"
    command: sh -c "npm install && expo start"
    networks:
      - docker-network

networks:
  docker-network:
    driver: bridge

To generate the EXPO_TOKEN environment variable, you must follow Expo’s instructions: https://docs.expo.dev/accounts/programmatic-access/

Go to the following link to generate tokens: https://expo.dev/accounts/[account]/settings/access-tokens

Visit Expo.dev, log in with your account, and generate an Access Token:

Select the Personal Access Token option:

Now copy the token content and paste it into the EXPO_TOKEN variable

Once generated, we need to create the Dockerfile folder and the react_native file with the following content:

# Use a Node.js image as the base
FROM node:latest

# Install Android SDK and tools
RUN apt-get update && apt-get install -y \
wget \
unzip \
openjdk-11-jdk \
curl \
&& rm -rf /var/lib/apt/lists/*

# Install Android SDK

# Environment variables
ENV ANDROID_HOME=/opt/android-sdk-linux
ENV ANDROID_SDK_ROOT=/opt/android-sdk-linux
ENV PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools
ENV ANDROID_VERSION=30
ENV ANDROID_BUILD_TOOLS_VERSION=30.0.3

RUN wget https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip
RUN mkdir -p ${ANDROID_HOME}/cmdline-tools
RUN unzip commandlinetools-linux-9477386_latest.zip -d ${ANDROID_HOME}/cmdline-tools
RUN rm commandlinetools-linux-9477386_latest.zip
RUN mv ${ANDROID_HOME}/cmdline-tools/cmdline-tools ${ANDROID_HOME}/cmdline-tools/latest
ENV PATH=${PATH}:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools
RUN yes sdkmanager --licenses
RUN yes sdkmanager --update
RUN yes sdkmanager "platform-tools"
RUN yes sdkmanager "platforms;android-${ANDROID_VERSION}"
RUN yes sdkmanager "build-tools;${ANDROID_BUILD_TOOLS_VERSION}"
RUN yes sdkmanager "extras;android;m2repository"
RUN yes sdkmanager "extras;google;m2repository"
RUN yes sdkmanager "extras;google;google_play_services"

# Set up a working directory
WORKDIR /app

# Install JDK
#RUN apt-get update && apt-get install -y openjdk-11-jdk

# Configure JAVA_HOME
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
# Install Expo CLI and EAS CLI globally
RUN npm install -g expo-cli && \
npm install -g eas-cli

# Expose port 3000 for Expo
EXPOSE 3000

# Keep the container running and waiting for commands
CMD ["/

Leave a Comment