问题描述
我使用以下命令来运行容器:
I used the following command to run the container :
docker run -p 3333:3333 -d maill/node-web-app
这是docker ps的结果:
Here is the result of 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服务器时,它不起作用.
However when I try to access webserver on host using localhost:3333 it doesn't work.
我正在使用Windows 10专业版.
I am using windows 10 pro.
docker日志musing_fermi
显示:
DONE Compiled successfully in 3541ms16:04:50 | OPEN localhost:3000
Dockerfile:
Dockerfile :
FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm i
COPY . .
EXPOSE 3333
CMD [ "npm", "run", "dev" ]
package.json:
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"
}
}
推荐答案
根据目前为止您所提出的问题,并且您有来自容器日志的 OPEN localhost:3000
,我猜您的应用程序正在 localhost
上侦听.这是容器外部的!= localhost
.您需要将应用程序配置为侦听容器内的 0.0.0.0
.
Based on what you have in the question so far, and that you have OPEN localhost:3000
coming from your container logs, I'd guess your application is listening on localhost
. This is != localhost
outside the container. You need to configure your application to listen on 0.0.0.0
inside the container.
这篇关于无法使用Docker访问Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!