Ad space (banner)
AD

Got the fundamentals? A structured Docker course is a fast way to level up.

Find Docker courses on Udemy

Affiliate link. Costs you nothing extra.

🐳Docker Lessons
Lesson 40 / 45

Creating a Network with docker network create

When containers need to talk to each other, use docker network create. It creates a network they can share.

The syntax is docker network create name. Containers on the same network can reach each other by container name.

Running docker network create mynet creates a network; containers started with --network mynet can then connect to each other by name.

A common stumble is trying to reach another container via localhost. Each container has its own network namespace — use the container's name instead.

In real work, a separate network per application keeps a web container and its database talking to each other and nothing else.

Docker
Try it (type this into the pseudo terminal)
docker network create mynet

🧑‍💻 You can type this command into the Docker pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)