Wednesday, October 4, 2017

Docker storage options

There are 2 options for storing data:
  • Within the container on its own filesystem - Not recommended for write heavy workloads
  • Outside the container

There are 3 options for mounting data from docker host:
  • Volumes
  • Bind mount
  • Tmpfs mount



Volumes

  • Stored on host filesystem
  • Managed by docker (/var/lib/docker/volumes/
  • Option recommended by docker
  • Can create named volumes or anonymous volumes
  • Support use of volume drivers that allow you to write data outside container. For eg Flocker, Convoy, sshfs etc See list here
  • Good option when sharing data between containers
  • Reference: https://docs.docker.com/engine/admin/volumes/volumes/

Bind mounts


Tmpfs mount


Performance Difference

Following shows performance of different mount options on Ubuntu instance on AWS t2.micro. (Doesn't include volume driver option as it will vary from driver to driver). Look for kB/s or MB/s
Reference: https://github.com/moby/moby/issues/21485

On host
ubuntu@host:~/nks$ sudo time dd if=/dev/zero of=/home/ubuntu/nks/out.txt bs=512 count=1000 oflag=dsync
1000+0 records in
1000+0 records out
512000 bytes (512 kB, 500 KiB) copied, 1.91264 s, 268 kB/s
0.02user 0.00system 0:01.91elapsed 1%CPU (0avgtext+0avgdata 2032maxresident)k
0inputs+8000outputs (0major+82minor)pagefaults 0swaps


Named volume
ubuntu@host:~/nks$ sudo docker volume create my-vol
my-vol
ubuntu@host:~/nks$ sudo docker volume ls
DRIVER              VOLUME NAME
local               my-vol
ubuntu@host:~/nks$ sudo docker run --rm --net=none --log-driver=none --read-only -v "my-vol:/nks" ubuntu bash -c "time dd if=/dev/zero of=/nks/out.txt bs=512 count=1000 oflag=dsync"
1000+0 records in
1000+0 records out
512000 bytes (512 kB, 500 KiB) copied, 1.90823 s, 268 kB/s

real 0m1.909s
user 0m0.000s
sys 0m0.028s

Host bind mount

ubuntu@host:~/nks$ sudo docker run --rm --net=none --log-driver=none --read-only -v "/home/ubuntu/nks:/nks" ubuntu bash -c "time dd if=/dev/zero of=/nks/out.txt bs=512 count=1000 oflag=dsync"
1000+0 records in
1000+0 records out
512000 bytes (512 kB, 500 KiB) copied, 2.10316 s, 243 kB/s

real 0m2.104s
user 0m0.028s
sys 0m0.000s

tmpfs mount

ubuntu@host:~/nks$ sudo docker run --rm --net=none --log-driver=none --read-only --mount type=tmpfs,destination=/nks ubuntu bash -c "time dd if=/dev/zero of=/nks/out.txt bs=512 count=1000 oflag=dsync"
1000+0 records in
1000+0 records out
512000 bytes (512 kB, 500 KiB) copied, 0.000757215 s, 676 MB/s

real 0m0.001s
user 0m0.000s
sys 0m0.000s
ubuntu@host:~/nks$
 

Storing data within container

  • Data is not persistent across container lifecycle
  • Inefficient for write heavy workloads due to disk block allocation and write through storage drivers
  • Pick driver that works best for you. Choice may be limited by the OS.
  • Reference: https://docs.docker.com/engine/userguide/storagedriver/




4 comments:

soumya said...

Your information is really superb thanks for sharing good information share more content on Devops Online Training Bangalore

Blog | Paradise Tehsoft said...

Great Article. I am a beginner & learning Various technologies.And side by side I write a blog to save my information.you can visit my blog here: What is Docker volume | What Does Dockers Volume Create?

DevOps said...

Thanks for posting such useful information. You have done a great job.
Docker and Kubernetes Training
Kubernetes Online Training
Docker Online Training

Sowmiya R said...

very useful blog

oracle training in chennai

oracle training institute in chennai

oracle training in bangalore

oracle training in hyderabad

oracle training

hadoop training in chennai

hadoop training in bangalore