Docker for Mac file access performance

If you’ve been reading File access in mounted volumes extremely slow , then you know that using shared volumes (from host filesystem) in Docker for Mac is quite hard and slow. But there’s a work-around if you don’t want to install any 3rd party software or configurations. Meet docker-machine-nfs.

Let’s test write performance on containers without and with shared volumes in Docker for Mac.

$ docker run -it --rm alpine sh
/ # time dd if=/dev/zero of=speedtest bs=1024 count=100000
100000+0 records in
100000+0 records out
real 0m 0.23s
user 0m 0.03s
sys 0m 0.20s
/ # # Pretty fast isn't it? ok, let's share a volume
/ # exit
$ # My current `pwd` is /Users/tpires
$ docker run -it --rm -v `pwd`:`pwd` -w `pwd` alpine sh
/Users/tpires # time dd if=/dev/zero of=speedtest bs=1024 count=100000
100000+0 records in
100000+0 records out
real    0m 23.93s
user    0m 0.32s
sys     0m 1.40s
/Users/tpires # # What happened here?! From 0.23s to 23.93s?!

Don’t give up just yet, docker-machine-nfs to rescue!

$ brew install docker-machine-nfs
$ docker-machine-nfs dev
$ # Follow the instructions to install and give a name to your machine
$ # After installation
$ eval $(docker-machine env dev)
$ # Let's repeat the previous test
$ # First without shared volume
$ docker run -it --rm alpine sh
/ # time dd if=/dev/zero of=speedtest bs=1024 count=100000
100000+0 records in
100000+0 records out
real    0m 0.21s
user    0m 0.02s
sys     0m 0.18s
/ # # Still pretty fast isn't it? ok, now test with shared volume
/ # exit
$ docker run -it --rm -v `pwd`:`pwd` -w `pwd` alpine sh
/Users/tpires # time dd if=/dev/zero of=speedtest bs=1024 count=100000
100000+0 records in
100000+0 records out
real    0m 0.93s
user    0m 0.01s
sys     0m 0.11s
/Users/tpires # # Sweet!!

But this isn’t the only approach to try to solve this problem, here is a shortlist:

Leave a comment

Filed under Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s