简体   繁体   English

如何在主机上访问docker app?

[英]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.

相关问题 如何从主机上的虚拟机访问 docker 应用程序? - How to access docker app from virtual machine on host? Docker for Windows 10如何访问主机 - Docker for Windows 10 how to access host machine 如何从容器化的 angular 应用程序中访问我的 docker 主机的 IP - How do I access my docker host machine's IP from within an angular app that is containerized 如何在虚拟机中访问 Django Docker 应用程序? - How to access Django Docker app in a Virtual Machine? 如何从主机访问Docker容器中的目录? - How to access a directory in docker container from host machine? docker(Mac / Windows):如何从容器访问主机服务? - docker(Mac/Windows): how to access host machine service from the container? 如何从主机访问在 docker 容器中运行的 mysql? - How to access mysql running in docker container from host machine? 如何在Docker中配置主机以访问Apache ServeName - How to configure host machine to access Apache ServeName in Docker 如何在主机上运行Nginx的情况下在Docker容器中运行Rails应用程序? - How to run rails app in docker container with nginx running on host machine? 如何将 Rails 应用程序连接到主机上的 docker postgres - how to connect Rails app to docker postgres on host machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM