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.
This should work: Here is the same steps I performed with my nginx container:
Copied an index.php file into ~/dockervolume/deus:
And browsed my public IP from my phone:
Derp. I was using the following before in my Node.js application:
I changed it to:
Now it's working. The reason I used
127.0.0.1
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.