[英]How to access docker app in the host machine?
I am trying to dockerize my angular app. 我正在尝试将我的有角度的应用程序码头化。 Below is my docker file, but I could not access the app in the port 4200. I don't know what is wrong in my configuration. 以下是我的docker文件,但是我无法在端口4200中访问该应用程序。我不知道我的配置有什么问题。 It is angular-cli app. 这是angular-cli应用程序。 Can you please help me find it? 你能帮我找到它吗?
FROM node:alpine
WORKDIR /app
COPY ./package.json .
RUN npm install
COPY . .
EXPOSE 80 4200
CMD ["npm", "run", "start"]
docker container run --publish 4200:4200 ngdockerapp docker容器运行-发布4200:4200 ngdockerapp
0ab397bc6233 ngdockerapp "npm run start" 37 seconds ago Up 35 seconds 80/tcp, 0.0.0.0:4200->4200/tcp ngdockerapp_ng_1
But I couldn't access the app in the host with 4200 port. 但是我无法在具有4200端口的主机中访问该应用程序。 I could see it is starting inside the container fine. 我可以看到它在容器内部正常启动。
Project Link: 项目链接:
https://github.com/manojp1988/ngDockerApp.git https://github.com/manojp1988/ngDockerApp.git
The problem is, you're using ng serve in the container without specifying the host. 问题是,您在容器中使用ng serve而不指定主机。 ng serve will by default only serve for 127.0.0.1. 默认情况下,ng服务将只为127.0.0.1服务。 you can change that by using the --host parameter. 您可以使用--host参数进行更改。
documentation about serve: https://github.com/angular/angular-cli/wiki/serve 有关服务的文档: https : //github.com/angular/angular-cli/wiki/serve
I added a pullrequest to your repo to fix it: https://github.com/manojp1988/ngDockerApp/pull/1 我向您的仓库中添加了一个pullrequest来对其进行修复: https : //github.com/manojp1988/ngDockerApp/pull/1
If you run docker exec -it <container_id> /bin/bash
, you can access the container. 如果运行docker exec -it <container_id> /bin/bash
,则可以访问该容器。 check this out How do I get into a Docker container? 检查一下如何进入Docker容器?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.