How to Identify and Reduce an 18 GB Docker Image Layer During docker push
This article walks through a step‑by‑step process to locate the 18.1 GB layer that makes docker commit and docker push extremely slow, using docker inspect, du, find, and docker diff, and explains common sources such as caches and overlay copy‑up so you can clean them and shrink the image.
Problem background : After launching a container from an existing image and compiling a project inside it, the author tried to create a new image with docker commit and push it with docker push. Both commands were very slow, and the push displayed a layer of 18.1 GB.
Solution workflow
1. Locate the 18.1 GB layer
Get the writable layer directory (UpperDir) of the container named daft-test:
UPPER=$(docker inspect -f '{{index .GraphDriver.Data "UpperDir"}}' daft-test)
echo "$UPPER"List the size of top‑level directories inside that UpperDir:
du -xhd1 "$UPPER" 2>/dev/null | sort -hThe output (shown in the first screenshot) reveals that /tmp, /home and /usr each occupy several gigabytes.
Drill down into a specific directory, for example /tmp:
du -xhd2 "$UPPER/tmp" 2>/dev/null | sort -h | tail -30The second screenshot shows many leftover Ray job files that consume a large amount of space; deleting them (and similarly cleaning other large directories) reduces the layer size.
2. Additional inspection commands
List the 50 largest files:
find "$UPPER" -xdev -type f -printf '%s\t%p
' 2>/dev/null |
sort -nr |
head -50 |
numfmt --field=1 --to=iecList files larger than 500 MB:
find "$UPPER" -xdev -type f -size +500M -printf '%s\t%p
' 2>/dev/null |
sort -nr |
numfmt --field=1 --to=iecShow what files have changed in the container:
docker diff daft-test > /tmp/daft-test.diff
head -100 /tmp/daft-test.diff
wc -l /tmp/daft-test.diffThe diff output uses A for added files, C for modified files, and D for deleted files.
3. Common reasons for oversized layers
Rust target/
Maven ~/.m2/repository
Gradle ~/.gradle
pip, uv, conda caches
Downloaded source packages, wheels, tar.gz
Debug/release intermediate files from builds
Log or test data
Modifying a large directory in the base image, triggering overlay2 copy‑upEspecially the last case: if the original image contains a 5 GB directory and only part of it is changed, overlay2 may copy the whole directory into a new layer, creating another 5 GB layer.
By cleaning the identified large directories and files, the image size drops dramatically, and both docker commit and docker push run much faster.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Big Data Technology Tribe
Focused on computer science and cutting‑edge tech, we distill complex knowledge into clear, actionable insights. We track tech evolution, share industry trends and deep analysis, helping you keep learning, boost your technical edge, and ride the digital wave forward.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
