Léo Coletta
Léo Coletta

Reputation: 1279

Cannot access web server using docker

I used the following command to run the container :

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

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

However when I try to access webserver on host using localhost:3333 it doesn't work.

I am using windows 10 pro.

docker logs musing_fermi shows:

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"
  }
}

Upvotes: 0

Views: 843

Answers (2)

zero298
zero298

Reputation: 26909

To go along with johnharris85's answer, add the following to your package.json:

From nuxt documentation on "How to edit HOST and PORT?"

You can configure the PORT with 3 different ways:

  1. ...
  2. ...
  3. Via a nuxt config in the package.json:

Inside your package.json:

"config": {
 "nuxt": {
   "host": "0.0.0.0",
   "port": "3333"
 }
},
"scripts": {
 "dev": "nuxt"
}

Upvotes: 0

johnharris85
johnharris85

Reputation: 18966

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.

Upvotes: 2

Related Questions