World map

 

BM: Baca dalam Bahasa Melayu

World D3: Lockers & Phone Lines

Settings in env files

You will learn: to hand a container many settings at once with --env-file.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

A long docker run line with four -e flags. env prints the four settings inside the box. Docker transcript: $ docker run --rm -e SHOP_NAME=Kedai -e TZ=Asia/Kuala_Lumpur -e CURRENCY=MYR -e OPEN_HOUR=8 alpine:3.22 env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=5b6ec9c12399 SHOP_NAME=Kedai TZ=Asia/Kuala_Lumpur CURRENCY=MYR OPEN_HOUR=8 HOME=/root

Your laptop~/shop

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB

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

Four settings, four -e flags. One typo and the shop breaks. Your shell history keeps every value, too.

Watch

Tap the line Docker skips.

0 of 1 found

An env file: A settings card: one NAME=value per line, handed over with --env-file. is a settings card: one NAME=value per line. --env-file shop.env hands the whole card to the box.

Try it

Start app with the whole settings card, shop.env.

Your laptop~/shop

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB

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

Predict

quoted.env says SHOP_NAME="Kedai Kancil". What does the app get?

Pick one answer.

Check

spaces.env has SHOP_NAME = Kedai Kancil. docker run refuses it: variable 'SHOP_NAME ' contains whitespaces. Docker transcript: $ cat spaces.env SHOP_NAME = Kedai Kancil $ docker run --rm --env-file spaces.env alpine:3.22 env docker: --env-file: invalid env file (spaces.env): variable 'SHOP_NAME ' contains whitespaces Run 'docker run --help' for more information

Your laptop~/shop

  • No open hatches

Lunchboxes (containers)

  • No containers yet

Frozen packs (images)

  • alpine:3.221 layers · 12.9MB

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

Real error: variable 'SHOP_NAME ' contains whitespaces. Plain words: no spaces around the = sign.

Check

Is this a good line for an env file?

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

1 / 5TZ=Asia/Kuala_Lumpur
TZ=Asia/Kuala_Lumpur

You did it!

You can now hand a container its settings in one file.

Go deeper (optional)

A line with only NAME copies that value from your laptop, if it is set. Compose reads .env files with its own rules: World D4. Does your env file hold a password? Keep it out of Git: put it in .gitignore.

Real rep (optional):

Real mission

  1. printf "SHOP_NAME=Kedai Kancil\nTZ=Asia/Kuala_Lumpur\n" > shop.env
  2. docker run --rm --env-file shop.env alpine:3.22 env
  3. echo "*.env" >> .gitignore

0 of 3 steps done · Your ticks are saved.