Docker Container Size Much Greater Than Actual Size

Docker taking much more space than sum of containers, images and volumes

You have two containers that are eating your storage. Those containers must be running, because you said you already ran docker system prune. Otherwise /var/lib/docker/containers would be empty.

So check why are those two consuming so much. Probably they are logging too much to stdout.

Why are Docker container images so large?

As @rexposadas said, images include all the layers and each layer includes all the dependencies for what you installed. It is also important to note that the base images (like fedora:latest tend to be very bare-bones. You may be surprised by the number of dependencies your installed software has.

I was able to make your installation significantly smaller by adding yum -y clean all to each line:

FROM fedora:latest
RUN yum -y install nano && yum -y clean all
RUN yum -y install git && yum -y clean all

It is important to do that for each RUN, before the layer gets committed, or else deletes don't actually remove data. That is, in a union/copy-on-write file system, cleaning at the end doesn't really reduce file system usage because the real data is already committed to lower layers. To get around this you must clean at each layer.

$ docker history bf5260c6651d
IMAGE CREATED CREATED BY SIZE
bf5260c6651d 4 days ago /bin/sh -c yum -y install git; yum -y clean a 260.7 MB
172743bd5d60 4 days ago /bin/sh -c yum -y install nano; yum -y clean 12.39 MB
3f2fed40e4b0 2 weeks ago /bin/sh -c #(nop) ADD file:cee1a4fcfcd00d18da 372.7 MB
fd241224e9cf 2 weeks ago /bin/sh -c #(nop) MAINTAINER Lokesh Mandvekar 0 B
511136ea3c5a 12 months ago 0 B

Analyzing docker image size

docker history <image_name>
prints the size of each docker layer.

credit to Generous Badger comment.

Why is a new docker image the same size of the original one from which the commit was made?

you may remove the first image with a force,

docker image rm -f $IMAGE_ID

As for the same size, it depends mainly on your changes, you can check if they match exactly on a byte level with:

docker image inspect IMAGE_NAME:$TAG --format='{{.Size}}'

How to analyze disk usage of a Docker container

To see the file size of your containers, you can use the --size argument of docker ps:

docker ps --size


Related Topics



Leave a reply



Submit