World map

 

BM: Baca dalam Bahasa Melayu

World D1: First Containers

Settings with -e

You will learn: to hand a container its settings with -e, and to read what it asks for.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

docker run starts a Postgres box called db. A moment later docker ps -a shows db Exited (1). Docker transcript: $ docker run -d --name db postgres:18-alpine f8e4773339ff69b8134322177bb70f78a323bebd8ea9c74cf88b43d965be38c6 $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f8e4773339ff postgres:18-alpine "docker-entrypoint.s…" 3 seconds ago Exited (1) 3 seconds ago db

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • postgres:18-alpine9 layers · 433MB

0 containers (0 running), 2 images, 0 lockers.

You start a database box, db. A second later it says Exited (1). Something is missing. But what?

Try it

Ask db why. Read its logs.

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • dbfailed (exit 1)
    from postgres:18-alpine no name → /var/lib/postgresql

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • postgres:18-alpine9 layers · 433MB · in use

Lockers (volumes)

  • 618a61fe96bb… (no name)0 files · used by db

1 containers (0 running), 2 images, 1 lockers.

Watch

docker run with -e NAME=Aina starts a box. Inside, printenv NAME prints Aina. Docker transcript: $ docker run --rm -e NAME=Aina alpine:3.22 printenv NAME Aina

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • nginx:1.30-alpine8 layers · 93.5MB

0 containers (0 running), 2 images, 0 lockers.

-e sticks a note on the lunchbox lid. The note is an environment variable: NAME=Aina sets NAME to Aina. The app inside reads it.

Try it

Build the command that gives db its password.

Tap the pieces in the right order.

…

Try it

Fix db. Remove the broken box. Then start a new one with a password.

Your laptop~

  • No open hatches

Lunchboxes (containers)

  • dbfailed (exit 1)
    from postgres:18-alpine no name → /var/lib/postgresql

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB
  • postgres:18-alpine9 layers · 433MB · in use

Lockers (volumes)

  • 618a61fe96bb… (no name)0 files · used by db

1 containers (0 running), 2 images, 1 lockers.

Predict

You gave db -e POSTGRES_PASSWORD=secret. Does the postgres meal pack change?

Pick one answer.

Check

Will Postgres find its password? Swipe each one.

Swipe right for good, left for needs work. Or use the buttons.

1 / 4-e POSTGRES_PASSWORD=secret
-e POSTGRES_PASSWORD=secret

You did it!

You can now hand a container its settings with -e.

Go deeper (optional)

docker inspect -f '{{.Config.Env}}' db lists every note on a box. Anyone who can run Docker can read them. So keep real passwords out of -e on shared machines. World D3 shows safer ways. -e NAME with no value copies NAME from your laptop.

Real rep (optional):

Real mission

  1. docker run --rm -e NAME=you alpine:3.22 printenv NAME
  2. docker run -d --name db -e POSTGRES_PASSWORD=secret postgres:18-alpine
  3. docker logs db
  4. docker rm -f db

0 of 4 steps done · Your ticks are saved.