Search code examples
dockerhttpserver

Getting the empty response from the server even when the container is port mapped in docker


I am trying to start my application using the http-server through npm start. It is working fine in the localhost but when i deploy the same application through docker container (port-mapped) , it doesn't appear in my local browser.

I have a directory inside my docker container(Ubuntu) which is runned through the command docker run -it -p 8001:5500 ubuntu. I have installed everything inside my container - npm, vim editor ,etc.

My package.json file is

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "http-server -a localhost -p 5500"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "concurrently": "^5.0.2",
    "http-server": "^0.12.1"
  }
}

After that i have done npm install and then executed the command npm start. The output of the command is :

enter image description here

But when i am trying to open my application in chrome browser it is throwing me an empty response.

enter image description here

Also when i am running the same application through my localhost it is accessible. enter image description here

Why i am not able to access the server through the port mapping of docker container.??


Solution

  • localhost inside container won't be accessible from outside the container. Run your server on 0.0.0.0 inside the container.