Your DevOps study space

Real explanations. Videos with tests. Fresh exams every time. Keep the streak alive and watch the XP stack up.

Volumes, networks & Compose in practice · Docker Docs · StackwisePlanDevOps Volumes, networks & Compose in practice · Docker Docs · StackwiseCodePython Volumes, networks & Compose in practice · Docker Docs · StackwiseBuildDocker Volumes, networks & Compose in practice · Docker Docs · StackwiseTestDevOps Volumes, networks & Compose in practice · Docker Docs · StackwiseReleaseGit Volumes, networks & Compose in practice · Docker Docs · StackwiseDeployKubernetes Volumes, networks & Compose in practice · Docker Docs · StackwiseOperateLinux Volumes, networks & Compose in practice · Docker Docs · StackwiseMonitorDevOps

Pick a topic

Eight tracks, each with docs, a cheat sheet, videos and tests.

How it works

One loop, repeated until it sticks.

Jump back in

Picked up from where you left off.

Free forever

Your DevOps journey starts with one click.

Sign in with Google or GitHub to open every chapter, video, test and challenge. Your progress is saved wherever you learn.

Volumes, networks & Compose in practice

Containers are meant to be thrown away, but your data isn't, and your containers need to find each other. This chapter covers the three ways to store data, how Docker networks and container DNS work, and a realistic Compose setup you can copy for your own projects.

Three kinds of mounts

container/var/lib/postgresql/data/app/tmpnamed volumepgdata, Docker-managedbind mounta host folder you picktmpfsRAM only, gone on stopdatabase filescode in developmentscratch files
Anything written inside a container without a mount disappears with the container. Pick the mount by who owns the data and how long it must live.
TypeExampleLivesUse it for
Named volume-v pgdata:/var/lib/postgresql/dataManaged by Docker (under /var/lib/docker/volumes on Linux)Database files, anything the app owns
Bind mount-v "$(pwd)":/appA folder you choose on the hostLive-editing code in development, config files
tmpfs--tmpfs /tmpRAM only (Linux), gone on stopScratch files, things that must never hit disk

Two differences worth knowing. An empty named volume is first filled with whatever the image has at that path; a bind mount simply hides it. And with -v, a host path that doesn't exist is silently created as an empty root-owned folder, while the longer --mount type=bind,src=...,dst=... syntax fails with an error instead. Add :ro to mount read-only: -v "$(pwd)/nginx.conf":/etc/nginx/nginx.conf:ro.

$ docker volume create pgdata
$ docker volume ls
$ docker volume inspect pgdata      # shows the Mountpoint on the host
$ docker volume rm pgdata           # only if no container uses it

Backing up a volume

Start a throwaway container that mounts the volume and your current folder, and tar one into the other:

# backup
$ docker run --rm -v pgdata:/data:ro -v "$(pwd)":/backup alpine \
    tar czf /backup/pgdata.tar.gz -C /data .
# restore into a (new, empty) volume
$ docker run --rm -v pgdata:/data -v "$(pwd)":/backup alpine \
    tar xzf /backup/pgdata.tar.gz -C /data
Copying a live database's files can give you a broken backup. Stop the database first, or use the database's own dump tool: docker exec db pg_dump -U app app > app.sql.

Networks and DNS by container name

Containers on the default network (called bridge) can only reach each other by IP. On a network you create, Docker runs a built-in DNS server, so containers find each other by name:

$ docker network create appnet
$ docker run -d --name db --network appnet -e POSTGRES_PASSWORD=example postgres:16
$ docker run --rm --network appnet alpine ping -c 2 db     # "db" resolves
$ docker network ls                   # bridge, host, none + yours
$ docker network inspect appnet       # subnet and the containers attached
$ docker network connect appnet web   # attach an already-running container

Other drivers: host shares the host's network directly (no isolation, no -p needed; Linux only) and none gives no network at all.

Publishing ports

Containers on the same network talk to each other on the container port directly (db:5432); no publishing needed. -p is only for traffic from outside Docker:

$ docker run -d -p 8080:80 nginx:1.27             # host 8080 -> container 80, all interfaces
$ docker run -d -p 127.0.0.1:8080:80 nginx:1.27   # only reachable from this machine
$ docker port <container>                          # show what is published
On Linux, a plain -p 8080:80 listens on every interface, and Docker writes its own firewall rules, so the port can be reachable from outside even if ufw seems to block it. Never publish a database port to the world; bind it to 127.0.0.1 or don't publish it at all.

A realistic compose.yaml

A web app and PostgreSQL, where the web container waits until the database actually accepts connections:

services:
  web:
    build: .
    ports:
      - "127.0.0.1:3000:3000"
    env_file:
      - web.env                        # vars injected into the container
    environment:
      DATABASE_URL: postgres://app:${POSTGRES_PASSWORD}@db:5432/app
    depends_on:
      db:
        condition: service_healthy     # wait for the healthcheck, not just "started"
    restart: unless-stopped

  db:
    image: postgres:16
    environment:
      POSTGRES_USER: app
      POSTGRES_DB: app
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app -d app"]
      interval: 5s
      timeout: 3s
      retries: 5
      start_period: 10s

volumes:
  pgdata:

Things to notice:

  • No version: line. It's obsolete in current Compose (v2 and later), which only prints a warning if you include it.
  • Compose creates a network called <project>_default automatically, so web reaches the database at host db. The database port isn't published at all.
  • depends_on conditions are service_started (the default), service_healthy and service_completed_successfully. It only controls startup order; your app should still retry if the database restarts later.

Two kinds of env files

  • A file named .env next to compose.yaml is read by Compose itself to fill in ${POSTGRES_PASSWORD} in the YAML.
  • env_file: web.env passes every line of that file into the container as environment variables.
# .env  (keep out of git and out of the image)
POSTGRES_PASSWORD=change-me

# web.env
LOG_LEVEL=info

docker compose config prints the final file with every variable filled in, which is the quickest way to spot a missing one.

Everyday Compose commands

$ docker compose up -d --build      # build if needed, start in the background
$ docker compose ps                 # state and health of each service
$ docker compose logs -f web        # follow one service's logs
$ docker compose exec db psql -U app -d app
$ docker compose restart web
$ docker compose down               # remove containers and network, KEEP volumes
$ docker compose down -v            # also delete volumes: the database is wiped

Questions

Pick an answer. Get it wrong and you can try again right away, no waiting. 10 questions per topic - pick a filter below, then use Recreate questions for a fresh set on that topic.

Fresh questions every time

Exam

A mixed test across the whole site, shuffled so you never know which topic comes next. When you submit, every mistake comes with the reason and a jump to the exact moment in the video that explains it.

30 questions 6 topics 20 minute limit Up to 70 XP
1–4 answer · ←→ move
History

Essay

0 / 200-250 words
Sample answer
History
0:00 / 0:00
Not started

on YouTube
Subscribe

Topic progress

Activity

Achievements

Settings

Your profile and your account.

Profile details

* Required. Saved in this browser until you sign in.

Letters, numbers, dots, dashes and underscores.
0 / 160

Account

Checking…

App

Install Stackwise on your phone or computer. It opens in its own window from your home screen, and the Docs and cheat sheets you've opened keep working without internet.

Only admins can see this

Dashboard

Sign-ups, activity, messages and reviews in one place.

Prove it

Certificates

Pass a topic's test and get a certificate with its own public page you can share or add to LinkedIn. Each test is 10 questions drawn at random and graded on the server; you need 8 right, you have 15 minutes, and you get one try per topic a day.

From first command to production

Linux for DevOps

A path through Linux the way DevOps engineers use it: ten stages, every command explained with its flags, examples, real output and mistakes, the combinations engineers chain together, and incidents worked through step by step. Practise everything in a safe lab folder.

Before the interview

Interview prep

Questions that come up in real DevOps interviews, with the kind of answer that lands. Say yours out loud first, then compare. Each one links to the chapter that goes deeper.

    Private to you

    My notes

    Everything you wrote down while watching and reading, in one place. Saved to your account, never shown to anyone.