- Intermediate
- Building images
How it works
RUN, COPY and ADD each add a layer holding only the files they changed. docker history lists the layers with their size. The size of the image is the sum of all its layers, those of the base image included.
What breaks
Deleting a file in a later instruction does not shrink the image: the file still sits in the earlier layer. Clean up in the same RUN that created the files (apt-get install … && rm -rf /var/lib/apt/lists/*), or leave the build tools behind with a multi-stage build.
In a terminal
docker history orders-api
docker images orders-api
See it break, then fix it
Write the Dockerfile or the compose file, type the docker commands, and watch a simulated server run them through reboots, upgrades and traffic. Free to start.