How to make a container visible to the external network and handle IP addresses in production
I have:
- Windows server on bare metal with Hyper-V
- Ubuntu server running Hyper-V
- Docker container with NGINX web application running on Ubuntu server.
Every time I run the Docker image, it gets a new IP address on the Docker0 network interface. For production, I don't know how to make the Docker container visible on the external network. I also don't know how to deal with the fact that the IP address changes every time the image is launched.
What is the correct way:
- to make Docker container visible on external network?
- handle Docker container IP addresses in a repeatable manner in production?
source to share
When you start a Docker container with docker run
, you must use a switch -p
for port forwarding, for example:
docker run -p 80:80 nginx
This will route port 80 from the Ubuntu server to port 80 in the Nginx container.
You should check the Docker documentation at https://docs.docker.com/reference/run/#expose-incoming-ports .
If you have multiple containers and links, you should use EXPOSE
in a Dockerfile as described here: https://docs.docker.com/reference/builder/#expose .
source to share