无法从docker映射的端口访问docker容器

我创build了一个docker容器,但是无法在docker映射的端口上运行它( http:// localhost:3000 )。 以下是我在我的应用程序中使用的dockerconfiguration的详细信息。

Docker版本:17.05.0-ce

操作系统:Ubuntu 16.04

我的Dockerfile:

FROM node:boron # Create app directory RUN mkdir -p /usr/src/app WORKDIR /usr/src/app COPY . /usr/src/app RUN npm install -g bower RUN npm install -g grunt-cli RUN npm install RUN bower install --allow-root #RUN grunt --force EXPOSE 3000 CMD ["grunt", "serve"] 

创builddocker集装箱:

 docker build -t viki76/ng-app . 

运行容器:

 docker run -p 3000:3000 -d viki76/ng-app 

docker工人ps:

 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS 21541171d884 viki/ng-app "grunt serve" 10 min ago Up 0.0.0.0:3000->3000/tcp 

编辑:

更新了Dockerfileconfiguration

 EXPOSE 9000 

$ docker run -p 9000:9000 viki76 / ng-app

 Running "serve" task Running "clean:server" (clean) task >> 1 path cleaned. Running "wiredep:app" (wiredep) task Running "wiredep:test" (wiredep) task Running "concurrent:server" (concurrent) task Running "copy:styles" (copy) task Copied 2 files Done, without errors. Execution Time (2017-05-17 13:00:13 UTC-0) loading tasks 189ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 88% loading grunt-contrib-copy 11ms ▇▇ 5% copy:styles 16ms ▇▇▇ 7% Total 216ms Running "postcss:server" (postcss) task >> 2 processed stylesheets created. Running "connect:livereload" (connect) task Started connect web server on http://localhost:9000 Running "watch" task Waiting... 

从Gruntfile.js

 connect: { options: { port: 9000, // Change this to '0.0.0.0' to access the server from outside. hostname: '0.0.0.0', livereload: 35729 }, 

请帮我解决它。 谢谢

我认为你的问题是grunt绑定到localhost:9000 – 这是容器的内部,所以你发布的端口不会有任何影响。

它需要在0.0.0.0:9000上进行监听 – 我不能告诉你什么是你的Gruntfile.js应该为此发生,但是它的Gruntfile.js看起来就像开箱即可,只能服务于从本地主机。

你做的都是对的,虽然我假设你的问题只是configuration。

默认情况下, grunt-serve服务于端口9000,而不是3000.您是否想尝试EXPOSE并发布该端口?

尝试在主机模式下运行容器:

 --net="host" 

运行容器时通过上述方法。