How to make a container visible to the outside network, and handle I.P addresses in production
- a Windows server on bare metal with Hyper-V
- Ubuntu server running in Hyper-V
- a Docker container with an NGINX web application running in Ubuntu server
Every time I run a Docker image it gets a new I.P. address on the Docker0 network interface. For production, I don’t know how to make the Docker container visible to the external network. I also don’t know how to handle the fact that the I.P address changes every time the image is run.
What’s the correct way to:
- make a Docker container visible to the external network?
- handle Docker container I.P. addresses in a repeatable way in production?
One Solution collect form web for “How to make a container visible to the outside network, and handle I.P addresses in production”
When you run your Docker container with
docker run, you should use the
-p switch to forward ports, for example:
docker run -p 80:80 nginx
This would route port 80 from the Ubuntu server to port 80 within the Nginx container.
You should check the Docker documentation on this at https://docs.docker.com/reference/run/#expose-incoming-ports.
When you have multiple containers and links, you should use
EXPOSE in the Dockerfile as documented here: https://docs.docker.com/reference/builder/#expose.