World map

 

BM: Baca dalam Bahasa Melayu

World D2: Recipes

Build context and .dockerignore

You will learn: what docker build sends to the kitchen, and how to leave secrets at home.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

The diary site is built with COPY . and served on 8080. curl asks for /notes.txt and gets the secret notes back. Docker transcript: $ docker build -t diary:1.0 . [+] Building 0.1s (7/7) FINISHED docker:default => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 90B 0.0s => [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: 217B 0.0s => [2/2] COPY . /usr/share/nginx/html/ 0.0s => exporting to image 0.1s => => exporting layers 0.0s => => exporting manifest sha256:0d5a886a786f4e692550502e61fe6a2b22542eb57 0.0s => => exporting config sha256:1fe3018005d8493b8c09a866ec4ef49aca2206d928e 0.0s => => exporting attestation manifest sha256:16f425bb5a0a067892c35bc1281ca 0.0s => => exporting manifest list sha256:6002bee7edbf3ff1d8f5ded132eb1f299d2f 0.0s => => naming to docker.io/library/diary:1.0 0.0s => => unpacking to docker.io/library/diary:1.0 0.0s $ docker run -d --name web -p 8080:80 diary:1.0 d01bb817dd03bbe494749e20379b172d1bbab0f0cd24a24526b0153ea2d1cc87 $ curl -s localhost:8080/notes.txt My secret notes: crush on Amir.

Your laptop~/diary

  • 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.

You shipped your diary site. A friend opens /notes.txt. Your secret notes are online! How did they get in?

Watch

Tap the line where your folder is sent.

0 of 1 found

docker build . sends the whole folder to the kitchen. That folder is the build context: The folder you send to the kitchen when you build. COPY can only take from it.. COPY . copies all of it, notes too.

Try it

Send it to the kitchen, or leave it at home?

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

      Try it

      A .dockerignore: A list of files to leave at home. They are never sent to the build. file lists what stays home. Make one, rebuild as diary:1.1, run it, then ask for /notes.txt.

      Your laptop~/diary

      • 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.

      Predict

      .dockerignore lists .env. The recipe says COPY . .. Is .env in the image?

      Pick one answer.

      Check

      Good .dockerignore lines? Swipe right for yes, left for “needs work”.

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

      1 / 5.git
      .git

      You did it!

      You can now choose what goes to the kitchen with .dockerignore.

      Go deeper (optional)

      A line starting with ! brings a file back: *.md then !README.md. You can list Dockerfile and .dockerignore too; the build still reads them. A smaller context also helps the cache, because fewer files can change.

      Real mission

      0 of 3 steps done · Your ticks are saved.