无法使用Docker访问Web服务器

时间:2018-07-02 16:09:10

标签: docker

我使用以下命令运行容器:

docker run -p 3333:3333 -d maill/node-web-app

这是docker ps的结果:

CONTAINER ID        IMAGE                COMMAND             CREATED             STATUS              PORTS                    NAMES
f26270107bfa        maill/node-web-app   "npm run dev"       49 seconds ago      Up 46 seconds       0.0.0.0:3000->3000/tcp   musing_fermi

但是,当我尝试使用localhost:3333访问主机上的Web服务器时,它不起作用。

我正在使用Windows 10专业版。

docker logs musing_fermi显示:

DONE Compiled successfully in 3541ms16:04:50 | OPEN localhost:3000

Dockerfile:

FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm i
COPY . .
EXPOSE 3333
CMD [ "npm", "run", "dev" ]

package.json:

{
  "name": "webapp-pst-horizon",
  "version": "1.0.0",
  "description": "Webapp pour les formations enedis",
  "author": "Léo Coletta",
  "private": true,
  "scripts": {
    "dev": "cross-env HOST=0.0.0.0 PORT=3333 nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate",
    "lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
    "precommit": "npm run lint"
  },
  "dependencies": {
    "@nuxtjs/axios": "^5.3.1",
    "@nuxtjs/proxy": "^1.2.4",
    "axios": "^0.18.0",
    "babel-polyfill": "^6.26.0",
    "cookie": "^0.3.1",
    "js-cookie": "^2.2.0",
    "nuxt": "^1.4.1",
    "vuetify": "^1.0.19",
    "webpack": "^3.1.0"
  },
  "devDependencies": {
    "babel-eslint": "^8.2.3",
    "cross-env": "^5.2.0",
    "eslint": "^4.9.0",
    "eslint-config-airbnb-base": "^12.1.0",
    "eslint-loader": "^2.0.0",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-vue": "^4.5.0",
    "stylus": "^0.54.5",
    "stylus-loader": "^3.0.2"
  }
}

2 个答案:

答案 0 :(得分:2)

根据目前为止您所提出的问题,并且您有OPEN localhost:3000来自容器日志,我想您的应用程序正在侦听localhost。这是容器外部的!= localhost。您需要将应用程序配置为侦听容器内的0.0.0.0

答案 1 :(得分:1)

要与johnharris85's answer一起使用,请将以下内容添加到7.43082e-25 9.70789e-20 5.20354e-15 9.8546e-11 5.36065e-07 0.000618363 0.0936591 0.811444 0.0936591 0.000618363 5.36065e-07 9.85459e-11 5.10703e-15 0 0 a discrete_distribution: 0: 1: 2: 3: 4: 5: 6: ********* 7: ******************************************************************************** 8: ********* 9: 10: 11: 12: 13: 14: 中:

来自nuxt documentation on "How to edit HOST and PORT?"

  

您可以通过3种不同的方式配置PORT:

     
      
  1. ...
  2.   
  3. ...
  4.   
  5. 通过package.json中的nuxt配置:
  6.   
     

在package.json内部:

package.json