HiveBrain v1.2.0
Get Started
← Back to all entries
patterndockerModerate

Do Docker containers take up space?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
dockercontainersspacetake

Problem

When I list my Docker images, I can see their sizes:

$ sudo docker image ls

REPOSITORY                TAG                          IMAGE ID       CREATED         SIZE
travisci/ci-ubuntu-1804   packer-1606831264-7957c7a9   0a7a71407638   8 days ago      15.6GB
travisci/ci-ubuntu-1804   packer-1593521720-ca42795e   6093ba41f031   5 months ago    12.3GB
travisci/ci-sardonyx      packer-1547455648-2c98a19    d1b323af5b2a   23 months ago   9.02GB


However, docker containers do not display the space used:

$ sudo docker container ls

CONTAINER ID  IMAGE         COMMAND       CREATED         STATUS         PORTS  NAMES
5794ae898b68  6093ba41f031  "/sbin/init"  10 minutes ago  Up 10 minutes         travis
762e3f8df2da  0a7a71407638  "/sbin/init"  4 hours ago     Up 4 hours            distracted_noyce


Of course, I understand that if you're writing to containers, some space will be used on the hard drive.

But when you create a container, does Docker actually clone the image before booting up the container? Or does it work with diffs, only storing the differences between the image and the current container disk state?

And, how can I see the actual disk space used by a container?

Solution

Yes, docker containers when they are running can take up some space as per your workload and application but as mentioned in the other answers - containers are built over layered filesystem therefore only extra space they consume is from some file/object they create/download during runtime which is not the part of base image like some debug log files, etc.

For ex. - When you run 100 containers of a base image of size 1GB, docker will not consume 100 GB of disk space as it leverages layered filesystem and top immutable layer is shared across all containers of same image.

When you stop and remove (yes!, remove explicitly or use --rm flag with docker run command) a container then it's space is reclaimed.

To check space used by containers (and other objects), you can use:

$ docker system df and for detailed info. use verbose flag $ docker system df -v

Initially when you start a container the SIZE column will show 0B but as soon as you start writing to the disk SIZE will change.

EDIT: added more info. as suggested by @Benjamin in comments

Context

StackExchange DevOps Q#12954, answer score: 12

Revisions (0)

No revisions yet.