You can find a good explanation of this concept here: https://github.com/docker/docker.github.io/issues/1520#issuecomment-305179362
From thaJeztah
The "size" and "virtual size" describe the amount of disk space used
by a container. Let me try and explain:
When starting a container, the image that the container is started
from is mounted read-only. On top of that, a writable layer is
mounted, in which any changes made to the container are written.
The read-only layers of an image can be shared between any container
that is started from the same image, whereas the "writable" layer is
unique per container (because: you don't want changes made in
container "a" to appear in container "b" smile)
Back to the docker ps -s
output;
The "size" information shows the amount of data (on disk) that is used
for the writable layer of each container The "virtual size" is the
total amount of disk-space used for the read-only image data used by
the container and the writable layer. The reason it's named "virtual
size", is that (as described earlier), the disk space for the
read-only layer(s) can be shared between containers, so only take up
disk space once (perhaps a different name ("shared" size?) would have
been better in hindsight, but naming is hard :) ). edit: virtual
actually shows the combined size of the readonly layer (the image),
and the writable layer of the container.
In the example below, I started 10 nginx containers;
All these containers use the same image, so the "Virtual size" (183MB
in the example) is used only once, irregardless of how many containers
are started from the same image - I can start 1 container or a
thousand; no extra disk space is used. The "Size" (2B in the example)
is unique per container though, so the total space used on disk is:
183MB + 10 * 2B
Be aware that the size shown does not include all disk space used for
a container. Things that are not included currently are;
- disk space used for log-files (if you use the json-file logging driver) - which can be quite a bit if your container generates a lot
of logs, and log-rotation (max-file / max-size logging options) is not
configured
- volumes used by the container
- disk space used for the container's configuration files (hostconfig.json, config.v2.json, hosts, hostname, resolv.conf) -
although these files are small
- memory written to disk (if swapping is enabled)
- checkpoints (if you're using the experimental checkpoint/restore feature)