Volumes, ports and networks
Containers are disposable; data and connectivity need explicit design.
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.
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
MediumConnect to a database by name
Run a postgres container named db on network edubyte, then run psql from another container using -h db.
BASH · starter
docker network create edubyteCheck 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 inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.