brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker history --no-trunc shows which command built each image layer

Docker
~/tips/tip-docker-history-no-trunc

docker history --no-trunc nginx:latest

Lists every layer of an image with the full command that created it and its size.

When an image is bigger than it should be, I want to know which step made it that way before I open the Dockerfile, if I even have the Dockerfile.

docker history --no-trunc nginx:latest

Each row is one layer: when it was created, the instruction that made it, and its size. Without --no-trunc the command column is cut off after a few dozen characters, which is exactly where the interesting part of a long RUN line lives.

Read it from the bottom up, because the oldest layer is at the bottom. A fat layer right after an apt-get install or a COPY . . is usually the culprit. It also works for images you only pulled and never built, which makes it a decent way to see what a third-party image does before you run it.

Add --format if you want only some columns, for example docker history --no-trunc --format "{{.Size}}\t{{.CreatedBy}}" IMAGE.

One caveat: the history stores the instruction text. A password or token passed with ARG, ENV or inside a RUN line is readable by anyone who can pull the image, so keep secrets out of those lines and use build secrets instead. Layers also do not tell you what is inside the files, only how they got there, so for contents you still need something like docker run --rm --entrypoint sh.

Further reading: docker image history reference

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link