Home > Back-end >  Does container size depend from size of docker volume?
Does container size depend from size of docker volume?

Time:06-11

I run the following docker image:

docker run -d -v home/myap:/home/node/appl example1 :latest

Let's assume that we run container example1 and it writes extensively into /home/node/app directory (1 GB every 1 minute). So in 10 minutes, we have written 10 GB.

If the docker container wasn't restarted am I right that size of the directory home/myapp as well as the size of docker container /home/node/app will be 10GB? So did our write operation take in total 20 GB of space?

Is there a way to keep the size inside of a docker container restricted, for example, no more than 3GB? Would Swarm or K8s help us with that?

CodePudding user response:

Am I right that size of the directory home/myapp as well as the size of docker container /home/node/app will be 10GB?

No, you are not. Your home/myapp directory will be mounted into the container – so instead of writing into the container, it will write into your home/myapp directory.

However, from the container's perspective, /home/node/app will be 10Gi in size – and say so if you jump into the container and have a look.

This follows UNIX mechanics, where you have a virtual file system, and storage mediums are mounted to different paths inside this virtual file system. In your case, said storage medium is the file path home/myapp, which is mounted to /home/node/app.

  • Related