带有Expo dockerized应用的Metro Bundle无法正常工作 [英] Metro bundler with Expo dockerized app is not working

查看:87
本文介绍了带有Expo dockerized应用的Metro Bundle无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Expo React Native应用程序进行docker化,以便团队合作伙伴中的任何人都可以下载存储库,然后进行 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 Bundle时出现问题,无法访问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 。依次只能从容器本身内部获得。没有端口暴露会帮助您。您需要以允许外部访问的方式设置端口绑定。例如

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 ,您应该没事。

这篇关于带有Expo dockerized应用的Metro Bundle无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆