How to make docker only use a private network to communicate with other hosts?

Hello! How can I configure Docker to exclusively use this private network? How to make the network interface that the docker creates docker0 only use the private network?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

At its simplest, you can bind a container to a specific network at runtime. For example, the nginx container exposes port 80. To bind that to port 8080 on your Droplet’s private network, run:

docker run -p nginx

Docker also provides many more complex networking options. For a high level overview, see:

For a deeper dive, take a look at “Understand Docker container networks” from the Docker docs.

Using some of the concepts covered there, you could also create a new bridge network that is available over your private IP address. For example,

docker network create  -o ""="" privnet

Now to specify that a container should use this new bridge network instead of using docker0, run it with:

docker run --net=privnet -p 8080:80 nginx