Building Docker Images for developers faster

by (January 19, 2017)

Posted in Containers  Tags:Alpine Linux, CI, DevOps, Docker

Lets take a project and Dockerize it. Then automate Docker building process, for example trigger it from Jenkins when tests passed. It will work but Docker build can be a long, very long process.

Real life example

Typical Django project, python:2.7.13-alpine as base image with Alpine Linux as container OS. On t2.medium Docker build will take about 15 minutes to complete. Most of this time pip install -r requirements.txt will run.

Using prepared image

There is a way to optimize it. Don’t use python:2.7.13-alpine, prepare an image with all requirements installed instead and use it as base image. It will work and will speedup process. But what if someone needs to update requirements it will require different base image. Some one needs to prepare base images and keep versioning them. Is there a way to do it in DevOps automated style? Yes there is.

Smart way to build development images

We can calculate md5 hash of requirements: cat requirements/* | sort | uniq | md5sum | awk '{ print $1 }' and tag an image we build with this hash. It will allow us to check if there is already an image with matching tag in Docker registry and if yes we can use it as base image and just add code, if not we would start a full Docker build.

Block Diagram

Having all this in place first build will take 15 minutes to complete but next builds will take only 2 minutes (numbers taken from one of our current project).

Let us know!

Contact details:

 

Services you are interested in: