To learn more, you can read Docker’s documentation on user-defined bridge networks. docker network create exampleĭocker run -net example -name nginx -d nginxĭocker network connect example -alias mongohost mongodb In most cases, Docker’s built in networking can handle this.ĭocker comes with a default network, but if you make your own, you can give containers aliases when launched in that network. This alias will resolve to the container’s private IP automatically. For example, the NGINX container here can access the MongoDB instance with the connection string mongodb://mongohost:27017. Most of the time, you’ll want a static IP to talk to one container from another, or from the host. If you want to make a static private IP address, you should consider if you need to use one at all. For example, binding port 80 (HTTP) on the host to point to an NGINX container: docker run -publish=80:8080 nginx While there are more advanced networking setups, this is by far the easiest and most common. You can “publish” ports on the Docker container to be accessible from the host. If you need to set up a public IP address for a container, you’ll want to use port bindings. There are two kinds of “static IP” private IP addresses used for internal networking inside a server, and public IP addresses used to connect outside the server, often over the internet. Assigning Docker containers static IP addresses is an easy way to make them more accessible. Static IP addresses don’t change when containers or services are stopped and started, making them useful for permanent networking.