Blazing Docker Deploys with this one neat trick!

Daniel Staudigel
The Human Effort
Published in
2 min readSep 8, 2016

Docker is a pretty amazing technology, solving a number of headaches in a really reliable way. However, it does have one common problem:

Docker can be really slow

This comes from one important reason: many deployment strategies rebuild the entire app, dependencies and all, every time. But, you say, caching makes that lightning fast! However, caching is not supported by a lot of cloud-service builders, and it doesn’t help at all when you make a minor change in your dependency tree.

What if you just need to change a few files? No asset compilation or dependency tree manipulation required. In normal Docker-land, you’re pretty hosed. With a lot of cloud-based deployment strategies, this can take a very long time. Additionally, even if you do support caching, often you have to upload your entire source tree again (because the step that wasn’t cached was a “copy everything” step). A few dozen megs of upload isn’t bad on a great connection, but it still seems crazy to me.

Enter docker patch!

The technique is simple:

  1. Pick a docker image to patch
  2. Figure out what the last modified file in that image is
  3. Copy every file in your dependency tree that is newer than that file into a container running that image
  4. Save the image as a new, patched image.

You can do this with a cloud-build image, or you can do it with a base image you have locally. Do not “layer” this technique, as it costs more time than it saves — just pick a reasonable built branch, and always patch that one, so there’s only ever one new layer to tack on to a base image.

Then push your patched image to your repo, and run this new image through whatever pipeline you wish. Once it is deployed to your production hosts, they will only have to download one new layer, a few dozen kilobytes of the text you needed changed.

Sweet!

An example of how one might use this deployment strategy for Rails applications, see https://github.com/TheHumanEffort/kubernetes-deployment-scripts/blob/master/rails/Makefile.

--

--