I've been reading: https://docs.docker.com/engine/userguide/networking/#user-defined-networks

I've created my own network (docker network create --driver bridge devils_network):

441be50f3792        bridge              bridge              local
0d73f7c6fe00        devils_network      bridge              local
8e189dda9fef        host                host                local
5ebca4a1e514        none                null                local

I run the container so:

docker run -it -d -v ~/dockervolume/deus:/srv/www --name deus --hostname deus --network=devils_network -p 80:8080 karl/node

And in the dockerfile expose port 8080:

EXPOSE  8080

I've attached a terminal session to the container and inspected the container to make sure the webserver is up and running:

root        17  0.0  0.1   4508   660 ?        S    22:46   0:00 sh -c NODE_PATH="$(pwd)" NODE_ENV=production node hello_world
root        19  0.0  4.3 882896 22004 ?        Sl   22:46   0:00 node hello_world

The webserver is utilizing port 8080 inside the docker container.

I'm running on a DigitalOcean droplet. If I start the server up directly on the host and not via a docker container it works.

  1. You need to inverse the mapping -p 80:8080 to -p 8080:80 The 1st port is on the host and the second is the container's.
  2. On your work/home network, make sure to redirect, in your router/fw, the port 8080 to your docker host port 8080.

This should work: Here is the same steps I performed with my nginx container:

docker network create --driver bridge devils_network

docker run -it -v ~/dockervolume/deus:/usr/share/nginx/html --name deus --hostname deus --network=devils_network -p 8080:80 ajnouri/nginx

Copied an index.php file into ~/dockervolume/deus:

And browsed my public IP from my phone:

enter image description here

  • Hi man! Thanks for the answer, I just realized I left out some important information regarding my question. The webserver is utilizing port 8080 inside the container. So I need to map hosts port 80 to the containers port 8080. Also running on DigitalOcean. – Karl Morrison Aug 16 '17 at 7:18

Derp. I was using the following before in my Node.js application:

const hostname = '';
const port = 8080;

I changed it to:

const hostname = '';
const port = 8080;

Now it's working. The reason I used is because I'm so used to using a reverse proxy (HAProxy) to deal with this. However I want the docker container to directly connect to the internet and not go through a reverse proxy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.