I'm trying to dockerize an Expo React Native app so anyone of my team partners could download the repo and then make a docker-compose up
and without effort have the same expo server running in their computers.
As far I make it possible to build the container and it is showing the same info it show up when I run it locally on my computer.
The problem arises when trying to start the metro bundler, url http://localhost:19002
is inaccessible. That doesn't happen with the port 19001, which is working perfectly.Besides, I tryed scanning the QR code with my iPhone device but it doesn't work neither, because is not finding the docker ip I guess.
I cannot figure out what I am doing wrong, and there is not so much information about dockerize expo in the web.
These are my dockerfile and docker-compose.yml
FROM node:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package*.json /usr/src/app/
COPY app.json /usr/src/app/
RUN npm install -g expo-cli
EXPOSE 19000
EXPOSE 19001
EXPOSE 19002
CMD npm i -f && npm start
version: '3.7' # Specify docker-compose version
# Define the services/containers to be run
services:
expo: # Name of the frontend service
container_name: expo-prestadores
build: ./ # Specify the directory of the Dockerfile
ports:
- 19000:19000 # Specify port-forwarding
- 19001:19001
- 19002:19002
volumes: # Mount host path in the container
- ./:/usr/src/app
- /usr/src/app/node_modules
Makes sense. Expo DevTools tells you it is running on localhost
in your container.
This means that in your container the Expo DevTools are only available to localhost
. Which in turn is only available from within the container itself. No port exposure will help you there. You need to set your port binding in a way that allows outside access. e.g. via the IP of the container in order to allow an expose statement to work.
In short, add the EXPO_DEVTOOLS_LISTEN_ADDRESS=0.0.0.0
environment variable like this
version: '3.7' # Specify docker-compose version
services:
expo: # Name of the frontend service
container_name: expo-prestadores
build: ./ # Specify the directory of the Dockerfile
ports:
- 19000:19000 # Specify port-forwarding
- 19001:19001
- 19002:19002
volumes: # Mount host path in the container
- ./:/usr/src/app
- /usr/src/app/node_modules
environment:
- EXPO_DEVTOOLS_LISTEN_ADDRESS=0.0.0.0
to your docker-compose.yml
and you should be fine.