7.1 What docker build leaves out

Read the tutorial. Build it yourself is the other way to read this part.

This walk goes through rahuldave/cheesecracker on GitHub. This part starts from the code at step-06. The code before this part

To look at this code on your machine, run these commands. The first one makes a clone, if this folder has none:

[ -d cheesecracker ] || git clone https://github.com/rahuldave/cheesecracker
cd cheesecracker
git fetch --quiet --tags --force origin
git switch --detach step-06
just setup

Our first file for Docker, .dockerignore, lists the files that never go into an image.

7.1 what docker build leaves out

Docker runs programs in containers. A container is a process with its own files, cut off from the rest of the machine. A Dockerfile lists the instructions that build an image. It starts from a base system, such as Debian with Python, and adds the files and the commands. docker build makes the image, and docker run starts a container from it. On macOS and Windows, the app Docker Desktop runs Docker.

docker build sends the files of the folder to Docker. The folder has .venv, the caches of the tools, git and maybe secrets. None of them belongs in an image. .dockerignore lists them.

± See the new file .dockerignore

The new file .dockerignore lists .venv/, the caches of pytest, ruff and coverage, .git/, secrets/ and .env.

cat .dockerignore

cat prints the list.

What changed

  • .dockerignore: what docker build never sends to Docker. New, 10 lines. The file
    • look at .venv/

The diff of .dockerignore
@@ -0,0 +1,10 @@
+# What docker build never sends to Docker: the environment, the caches, git and the secrets
+.venv/
+__pycache__/
+.pytest_cache/
+.ruff_cache/
+.coverage
+htmlcov/
+.git/
+secrets/
+.env

This change on GitHub

This part ends at the code at 2a28a5c704d6, partway through step-07. The code after this part