Lesson 3.2

Container networking

On a user-defined network, containers resolve each other by name through the built-in DNS.

6mBeginner18k students

Overview

Containers find each other by name

On a user-defined network, containers resolve each other by name through the built-in DNS. An application connects to a database at its service name — no ip addresses, no discovery mechanism to build.

Publishing a port is only about reaching a container from the host. Two containers on the same network talk to each other without publishing anything, which is also the safer default.

From inside a container, localhost means that container. Trying to reach the host or a sibling that way is the most common networking mistake there is.

In this lesson you will:

  • Connect containers on a user-defined network
  • Resolve a service by container name
  • Distinguish host ports from container ports

Resources

Previous Lesson
Next Lesson
Container networking — Docker Essentials — Vertex