LESSON 03 / 4·2 min readIntermediate

Volumes vs networks vs Compose?

01 Understand02 Recall03 Prepare

Understand the concept

Volumes provide storage independent of a container's disposable writable layer. Container networks define communication paths and service-name resolution, while Compose declares a set of cooperating containers and their configuration. Together they make a local multi-service setup repeatable without placing every service in one container.

Important ideas

  • Volumes persist data independently of a container's writable layer.

  • Networks let containers communicate; localhost means that same container.

  • Compose describes multiple services, networks and volumes in one configuration.

  • Persisting a database volume is not a backup; deletion, corruption and operator mistakes still require a recovery plan.

Example — two Compose services:

  • App service: api; database service: db; both join the same Compose network.
  • The app connects to db:5432, because service-name DNS resolves the database container.
  • A host mapping such as 5433:5432 lets a host client use port 5433; the app still uses port 5432 inside the network.
  • Database data belongs in a volume, with a separate tested backup procedure.
PAUSE & RECALL

Can you explain it without the notes?

Volumes vs networks vs Compose?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Volumes provide storage independent of a container's disposable writable layer. Container networks define communication paths and service-name resolution, while Compose declares a set of cooperating containers and their configuration. Together they make a local multi-service setup repeatable without placing every service in one container.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • A database's host port is for access from outside that network; peer containers normally use the service name and container port.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: How do I make a production container safer and smaller?

Adapted from 09_TESTING_GIT_DOCKER_CLOUD.md · “Volumes vs networks vs Compose?”. Examples are study fragments; framework behavior can depend on your version.