How to run local server in host?

I’ve just installed nodejs using docker, and I run a test server:

docker exec -i -t my-running-app bash
root@46593eb5df5c:/usr/src/app# npm start
npm info it worked if it ends with ok
npm info using npm@2.15.1
npm info using node@v4.4.3
npm info prestart foo@
npm info start foo@

> foo@ start /usr/src/app
> node server.js

Server running at

In the docker image, I am exposing port 8000, but I don’t know how would I browse into the node server inside container from the host?

  • For dummies approach to build image and run own code on Docker
  • Restart postgres in a docker environment
  • How to make docker volume update automatically?
  • how to redirect http to https in nginx docker elastic beanstalk
  • Docker architecture for hosting a PHP website
  • How do I get environment variables to persist into an imported Docker image
  • if I just browse to I get:

    This site can’t be reached refused to connect.

    I am on ubuntu 14.04, so, how would I view that deckorized server?

  • No executable found matching command “dotnet-/../.dll” when running dotnet core docker image in Azure Web App on Linux
  • Start a dependency unit in CoreOS
  • Java application cannot get IP address of the host in docker container with static IP
  • Unable to run shell command with docker?
  • Docker and UFW with real IP
  • docker pseudo file not showing swap memory information
  • 2 Solutions collect form web for “How to run local server in host?”

    First of all try putting all the container start up commands to Dockerfile (where you build you docker image), i.e. you need to npm start and to expose port 8000, you should add to Dockerfile:

    EXPOSE 8000
    CMD [ "npm", "start" ]

    You need to start you instance of the application with port mapping:

     docker run -p public_port:8000 -d my-running-app

    It will create a communication tunnel from “outside” world (public_port, could be the same – 8000, or whichever you need) to docker image

    You need to map your container Port to your Host port:

    docker exec -p 8000:3000

    for example maps your 8000 container port to your 3000 host port.

    By default Docker containers can make connections to the outside world, but the outside world cannot connect to containers. Each outgoing connection will appear to originate from one of the host machine’s own IP addresses thanks to an iptables masquerading rule on the host machine that the Docker server creates when it starts..

    Docker doc for binding Ports

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.