Docker machine executor cache workaround

docker
caching

#1

As it looks like it may be a while until Circle has docker image caching working on 2.0 I thought I’d share our current workaround for enabling caching on the machine executor.

This is in response to the following topics:






The issue with rebuilding comes from a security patch (in 1.10.1 I believe) which prevents the current system from using the buildcache from a pulled or loaded image. The additional functionality to re-enable this process landed in docker API 1.25 so we need to upgrade the version of docker running on the VM (there is a feature request for this already). The following build step upgrades to the latest version of docker community edition (API 1.26 as of the posting date) and takes about 30 seconds to run, this has not caused any adverse affect for us on Circle but YMMV.

steps:
      - type: shell
        name: Update docker
        command: |
          # Remove docker engine
          sudo apt-get remove docker-engine
          # Install docker
          curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
          sudo chmod 777 /etc/apt/sources.list.d/docker.list
          sudo echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu trusty stable" > /etc/apt/sources.list.d/docker.list
          sudo apt-get update -o Dir::Etc::sourcelist="sources.list"
          sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/docker.list"
          sudo apt-get install --yes docker-ce

Now to instruct docker to use a pulled or loaded image as a build cache you need to pass --cache-from to the docker cli (https://docs.docker.com/engine/reference/commandline/build/) or cachefrom parameter to the docker API (https://docs.docker.com/engine/api/v1.26/).

Caching should now work when pulling images from the registry or when following this process as we do:

  • Docker save image to tar
  • Cache tar file using cache step in circleci
  • Restore cache on next build
  • Docker load tar file
  • Pass cachefrom to docker build

#2

We natively support layer caching on the machine at this time: https://circleci.com/docs/2.0/docker-layer-caching/#docker-layer-caching-in-machine-executor


#3

Can you tell us what the additional fee is for the native solution?


#4