带有 Expo dockerized 应用程序的 Metro 捆绑器无法正常工作 [英] Metro bundler with Expo dockerized app is not working
问题描述
我正在尝试对 Expo React Native 应用程序进行 docker 化,以便我的团队合作伙伴中的任何人都可以下载 repo,然后制作 docker-compose up
并且毫不费力地在他们的服务器中运行相同的 expo 服务器电脑.
到目前为止,我可以构建容器,并且它显示的信息与我在计算机上本地运行时显示的信息相同.
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.
尝试启动metro bundler时出现问题,无法访问url http://localhost:19002
.端口 19001 不会发生这种情况,它工作得很好.此外,我尝试用我的 iPhone 设备扫描 QR 码,但它也不起作用,因为我猜没有找到 docker ip.
我无法弄清楚我做错了什么,并且网络上没有太多关于 dockerize expo 的信息.
这些是我的 dockerfile 和 docker-compose.yml
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
推荐答案
有道理.Expo DevTools 告诉您它正在容器中的 localhost
上运行.
Makes sense. Expo DevTools tells you it is running on localhost
in your container.
这意味着在您的容器中,Expo DevTools 仅对 localhost
可用.而这又只能从容器本身中获得.没有端口暴露会帮助你.您需要以允许外部访问的方式设置端口绑定.例如通过容器的 IP,以允许暴露语句工作.
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.
简而言之,像这样添加 EXPO_DEVTOOLS_LISTEN_ADDRESS=0.0.0.0
环境变量
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
到你的 docker-compose.yml
你应该没问题.
to your docker-compose.yml
and you should be fine.
这篇关于带有 Expo dockerized 应用程序的 Metro 捆绑器无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!