Crate Docker — DevOps

Pack a farmers' crate post app into containers: Dockerfile, volumes, networks, Compose, registry. 15 levels, right in the browser.

What you learn in this game

Docker wraps an app with everything it needs (the Node version, the libraries, the system files) into an image. An image that runs is a container. One image can become many containers. In Krat Docker every command runs on the real Docker Engine 29.9.2, on a Debian machine with no internet, and the terminal in the book copies its answers as they came.

The first line of a Dockerfile, FROM, picks the base image: your image's starting point, for example Alpine Linux with Node already in it. Every line below stacks on top of it. An app that runs on a laptop does not always run on a server, because the machines hold different things. Docker carries those things inside the image.

-p 9000:3000 forwards port 9000 on the server to port 3000 inside the container. The left number belongs to the server, the right one to the container. Two containers may both listen on port 3000 inside, because each container has a network of its own. What cannot be the same is the port on the server.

A Dockerfile is an image's recipe, one instruction per line, run from the top. Every instruction becomes a layer, and Docker keeps its result in the build cache. The next build reuses every layer that is exactly the same. COPY counts as the same when the files it copies are exactly the same.

The folder you build is sent whole to Docker as the build context. .dockerignore, next to the Dockerfile, names what is not sent, one pattern per line. What is not sent cannot get into the image through COPY.

A Dockerfile may have several FROMs. Each FROM starts a new stage from nothing, and only the last stage becomes the image. AS name names a stage, and COPY --from=name takes files from it. The build tools stay in the first stage; the final image carries only their result.