Docker Engine 29 reference · Images

docker history Command (Docker CLI)

Show the layers of an image and the instruction that created each, with sizes, to find what makes it big.

Docker Engine 29

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

docker history [OPTIONS] IMAGE

Parameters

ParameterDescription
--no-trunc Show full instructions.
--format TEMPLATE e.g. '{{.Size}} {{.CreatedBy}}'.

Examples

Layers and their sizes
printf 'FROM alpine:3.24\nRUN head -c 3000000 /dev/zero > /big.bin\nCMD ["ls", "-l", "/big.bin"]\n' > Dockerfile
docker build -q -t rc-ref-hist:1 . > /dev/null
docker history rc-ref-hist:1 --format '{{.Size}}\t{{.CreatedBy}}' | head -3 | cut -c1-70
docker image rm rc-ref-hist:1 > /dev/null

Output

0B	CMD ["ls" "-l" "/big.bin"]
3.01MB	RUN /bin/sh -c head -c 3000000 /dev/zero > /…
0B	CMD ["/bin/sh"]

Run this on your computer — see “Get Started” for setup.

Why secrets don't belong in ARG
printf 'FROM alpine:3.24\nARG TOKEN\nRUN test -n "$TOKEN"\n' > Dockerfile
docker build -q --build-arg TOKEN=s3cr3t -t rc-ref-hist:2 . > /dev/null
echo "build arg visible in history: $(docker history --no-trunc rc-ref-hist:2 | grep -c s3cr3t)"
docker image rm rc-ref-hist:2 > /dev/null

Output

build arg visible in history: 2

Run this on your computer — see “Get Started” for setup.

Was this page helpful?