node.js – 无法从docker映射的端口访问docker容器

前端之家收集整理的这篇文章主要介绍了node.js – 无法从docker映射的端口访问docker容器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我创建了一个docker容器,但无法在docker(http://localhost:3000)映射的端口上运行它.以下是我在我的应用中使用的泊坞窗配置的详细信息.

Docker版本:17.05.0-ce

Os:ubuntu 16.04

我的Dockerfile:

  1. FROM node:boron
  2. # Create app directory
  3. RUN mkdir -p /usr/src/app
  4. WORKDIR /usr/src/app
  5. COPY . /usr/src/app
  6. RUN npm install -g bower
  7. RUN npm install -g grunt-cli
  8. RUN npm install
  9. RUN bower install --allow-root
  10. #RUN grunt --force
  11. EXPOSE 3000
  12. CMD ["grunt","serve"]

创建docker容器:

  1. docker build -t viki76/ng-app .

运行容器:

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

docker ps:

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

编辑:

更新了Dockerfile配置

  1. EXPOSE 9000

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

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

来自Gruntfile.js

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

请帮我修理一下.
谢谢

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

它需要在0.0.0.0:9000上进行监听 – 我无法告诉你Gruntfile.js应该为此发生什么,但是看起来像是开箱即用,grunt服务只会服务来自localhost.

猜你在找的Docker相关文章