World map

 

BM: Baca dalam Bahasa Melayu

World D3: Lockers & Phone Lines

Never bake in secrets

You will learn: why a password in a Dockerfile leaks, and how to hand it over at run time.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

The Dockerfile has ENV DB_PASSWORD=kancil123. The build warns SecretsUsedInArgOrEnv. Any box from the image prints kancil123. Docker transcript: $ cat Dockerfile FROM nginx:1.30-alpine ENV DB_PASSWORD=kancil123 COPY site/ /usr/share/nginx/html/ $ docker build -t shop:1.0 . [+] Building 0.1s (7/7) FINISHED docker:default => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 120B 0.0s => WARN: SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "DB_PASSWORD") (line 2) => [internal] load metadata for docker.io/library/nginx:1.30-alpine 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [1/2] FROM docker.io/library/nginx:1.30-alpine@sha256:0e52bd054126cdc0 0.0s => => resolve docker.io/library/nginx:1.30-alpine@sha256:0e52bd054126cdc0 0.0s => [internal] load build context 0.0s => => transferring context: 135B 0.0s => [2/2] COPY site/ /usr/share/nginx/html/ 0.0s => exporting to image 0.1s => => exporting layers 0.0s => => exporting manifest sha256:77265d7416b79e6aa8d371cacd3f3215a929664ee 0.0s => => exporting config sha256:5a6636cf193c938e2901b31bb63b3efe1d79c93b0ad 0.0s => => exporting attestation manifest sha256:fc83d324dd5546609c3b107e62115 0.0s => => exporting manifest list sha256:8469b3576d7a624bdb8db40a60109fe99154 0.0s => => naming to docker.io/library/shop:1.0 0.0s => => unpacking to docker.io/library/shop:1.0 0.0s 1 warning found (use docker --debug to expand): - SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "DB_PASSWORD") (line 2) $ docker run --rm shop:1.0 printenv DB_PASSWORD kancil123

Your laptop~/shop

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • nginx:1.30-alpine8 layers · 93.5MB

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

The recipe says ENV DB_PASSWORD=kancil123. Docker even warns: SecretsUsedInArgOrEnv. Now every box from this image knows the password.

Watch

A secret: The locked spice box: private info like a token. Never put it in code. is the locked spice box. Never stir it into the recipe. Hand it over only when the dish is served. Sort these.

Drag a card into a box. Or tap the card, then tap the box.

      Predict

      You push shop:1.0 to a public registry. Who can read the password?

      Pick one answer.

      Check

      This is docker history for shop:1.0. Tap the line that leaks.

      0 of 1 found

      Every recipe line stays in the image’s history. Anyone can read it.

      Try it

      Start db. Hand it the password from db.env, at run time.

      Your laptop~/shop

      • No open hatches

      Lunchboxes (containers)

      • No containers yet

      Frozen packs (images)

      • postgres:18-alpine9 layers · 433MB

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

      Check

      Safe habit, or a leak?

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

      1 / 5

      Put .env files in .gitignore.

      Put .env files in .gitignore.

      You did it!

      You can now keep secrets out of your images.

      Go deeper (optional)

      Run-time env vars still show in docker inspect. Compose secrets arrive as files in /run/secrets.

      Where the story breaks: a locker isn’t truly outside. Volumes sit on the same disk, or in Docker Desktop’s VM. Lose the disk, lose the locker. Phone lines are only software. And an env var is no locked box.

      Real mission

      1. docker history --no-trunc <your-image>
      2. git check-ignore .env

      0 of 3 steps done · Your ticks are saved.