Dan Stutzman

Speed up Docker on EC2

Published 2014-07-29

I noticed that my Docker server was dramatically slower on an EC2 server than on a comparable server hosted on DigitalOcean. Slow, as in: 5 seconds to complete a trivial Dockerfile step instead of 0.1 seconds. Why?

An IRC user named deltab helpfully suggested to check which storage backend I was using. Sure enough, running docker info showed Storage Driver: devicemapper on the slow server and Storage Driver: aufs on the fast server.

A forum post by Robin Speekenbrink suggested that running the official Docker install script at get.docker.io could make Docker faster on AWS. Turns out he was right, thanks to this little excerpt:

          # aufs is preferred over devicemapper; try to ensure the driver is available.
          if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
            kern_extras="linux-image-extra-$(uname -r)"
          
            apt_get_update
            ( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true
          
            if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
              echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)'
              echo >&2 ' but we still have no AUFS.  Docker may not work. Proceeding anyways!'
              ( set -x; sleep 10 )
            fi
          fi
          

TL;DR If Docker is slow on EC2 and docker info returns Storage Driver: devicemapper, try running apt-get install -y -q linux-image-extra-$(uname -r). Afterwards you might have to restart Docker and recreate all your containers.