Table of Contents
Containerizing your Expo projects with Docker Compose can streamline your development process, ensure consistency across environments, and simplify deployment. This step-by-step guide will walk you through the process of setting up Docker Compose for your Expo app, making it easier to develop, test, and deploy.
Prerequisites
- Basic knowledge of Docker and Docker Compose
- Node.js and npm installed on your machine
- Expo CLI installed globally
- Existing Expo project or start a new one
Step 1: Create a Dockerfile
Create a Dockerfile in the root directory of your Expo project. This file will define the environment for your app.
Example Dockerfile:
FROM node:14-alpine
# Set working directory
WORKDIR /app
# Install Expo CLI
RUN npm install -g expo-cli
# Copy project files
COPY . .
# Install dependencies
RUN npm install
# Expose port 19000 for Expo
EXPOSE 19000
# Start Expo
CMD ["expo", "start", "--tunnel"]
Step 2: Create a docker-compose.yml File
In the root directory, create a docker-compose.yml file to define the service for your Expo app.
Example docker-compose.yml:
version: '3'
services:
expo:
build: .
ports:
- "19000:19000"
- "19001:19001"
- "19002:19002"
volumes:
- .:/app
environment:
- NODE_ENV=development
command: expo start --tunnel
Step 3: Build and Run the Container
Open your terminal in the project directory and run the following command to build and start your container:
docker-compose up --build
This command will build your Docker image and run the container, exposing the necessary ports for Expo development.
Step 4: Access Your Expo App
Once the container is running, you can access the Expo developer tools by opening http://localhost:19000 in your browser. Use your Expo Go app on your mobile device to scan the QR code displayed in the terminal or browser to run your app.
Additional Tips
- Use Volumes to sync code changes without rebuilding the container.
- Configure environment variables in
docker-compose.ymlfor different development environments. - For production, optimize your Dockerfile by reducing layers and removing unnecessary dependencies.
By containerizing your Expo project with Docker Compose, you create a portable, consistent development environment that simplifies collaboration and deployment. Happy coding!