Docker Community Forums

Share and learn in the Docker community.

Question on Container Storage


(Leo2018) #1

Hi, I am a new comer in Docker.
Here is a question about the disk space of container storage
Say I pull a oraclelinux:7.3 to my local env, and the size of it is 225MB,

[root@slc08acl limtan]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
oraclelinux 7.3 d42df3cd808c 2 months ago 225 MB

And the storage location of image and container is:
[root@slc08acl limtan]# du -h --max-depth=1 /scratch/docker/overlay/
238M /scratch/docker/overlay/ef25892fbf737bcebd42be6090f8828cea3a38f99ade782b772549145dfc42b6
238M /scratch/docker/overlay/

Now, I would like to start two containers. Per my understanding from this link, the major difference between a container and an image is the top writable layer.
The disk space consuming will be around 238M = image(238M) + two writable layers,
because the two containers shared the same files. And the extra space consuming is their writable layers.

Now I created two containers and check the disk space,

[root@slc08acl limtan]# docker run -itd d42df3cd808c
23f310035a66691f9ec2ea18f648a56c09adc8a51435b3357242136905f17846
[root@slc08acl limtan]# docker run -itd d42df3cd808c
d6c27c6190844d2f78e43ae53115837fc979252cd67e5c28aae09f48691a1e68
[root@slc08acl limtan]# du -h --max-depth=1 /scratch/docker/overlay/
238M /scratch/docker/overlay/df7480d641c62b61c5b5912420632f81e2f112ed42b2afa6519f1a15a2a02d22
227M /scratch/docker/overlay/582cbe9a3c12be8d46323ad5d6efcf6e42261985b01d0e093f4a72083f05bd10
40K /scratch/docker/overlay/df7480d641c62b61c5b5912420632f81e2f112ed42b2afa6519f1a15a2a02d22-init
227M /scratch/docker/overlay/ef25892fbf737bcebd42be6090f8828cea3a38f99ade782b772549145dfc42b6
40K /scratch/docker/overlay/582cbe9a3c12be8d46323ad5d6efcf6e42261985b01d0e093f4a72083f05bd10-init
692M /scratch/docker/overlay/

(Seem that two containers take 692MB)

When I stop the container and check again


(Now the disk space taking return to 238MB)

From the above result, I have following questions:
1.Why the two containers take 692 MB? It seems containers copy all the files from the image.
2.For the item /scratch/docker/overlay/ef25892fbf737bcebd42be6090f8828cea3a38f99ade782b772549145dfc42b6,
why the size will change from 238M -> 227M after we start the containers?
3. Why the disk space consuming will be different when the containers are in run/stop?

Any help or guidance will be really appreciated.


(Junius) #2

Container image size just includes the packages in the container. It does not cover the run time size.

You may want to check the oraclelinux container. It would mount a volume by default to store the data of oracle. Usually DB init will create some data on disk. It would be better to mount an external volume for DB data, instead of using the root directory.