Linux Labs

Containers: Docker and compose / Stage 7 of 11

Container networking: names and ports

Not running Starting usually ~20 s
Leave the lesson

Step 1 of 6 · on a machine · 6 min

The application cannot find its database

What you will learn

  • Find out from the log and the container's /etc/resolv.conf why a neighbour's name is not found.
  • Link containers with a Docker network of your own so they find each other by name.
  • Pick the address and port for connecting from a container to its neighbour and from the host.

The developers handed over two containers: the application app and a practice database db. The database listens on port 5432 and answers every connection with the line db: ok. Every three seconds the application connects to it by the name db and writes the result to its log. Both containers are running, yet the application complains that the database is missing.

See for yourself. As in the previous lessons, docker commands here go through sudo. “Start” launches both containers.

Exercise · look

Read the application log

Check that both containers are running, then read the app log.

First, predict

Both containers are Up. What does app write to its log?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

What does bad address 'db' in the app log mean?

  • A firewall gets in the way of connecting to an address, and there is no address here: nc found nowhere to connect to.

  • A refusal happens once there is an address and the connection has started. bad address means it never got that far: the name was not found.

  • sudo docker ps shows db as Up: the database is running.

bad address 'db' means nc found no address for the name db.

Ubuntu 24.04
Loading…