Docker Foundations·Ship the environment with the app

Volumes, ports and networks

Containers are disposable; data and connectivity need explicit design.

Beginner 14 min read Lesson 8 of 300 Challenge included
What you will be able to do
  • Use named volumes for databases and persistent uploads.
  • Use a user-defined bridge network for service-to-service traffic.
  • Publish only the ports that need host access.

In plain English

A volume survives container replacement. A bind mount maps a host path for development. Published ports expose a container to the host; containers on the same user-defined network resolve each other by service name.

terminalTerminal
docker network create edubyte
docker volume create pgdata
docker run -d --name db --network edubyte \
  -e POSTGRES_PASSWORD=secret \
  -v pgdata:/var/lib/postgresql/data \
  postgres:16-alpine
docker run --rm --network edubyte postgres:16-alpine \
  psql -h db -U postgres -c "select 1"
Your turn

Connect to a database by name

Medium

Run a postgres container named db on network edubyte, then run psql from another container using -h db.

BASH · starter
docker network create edubyte
Check your understanding before moving on.
Knowledge checkQuestion 1

How do containers on the same user-defined network find each other?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Compose a real stack
Lesson 8 of 300 · 0% of course