Difficulty: Beginner
Estimated Time: 10 minutes

In this scenario you will learn how to use Make for managing docker image creation.

Like source code, Docker images are required to be built, tested and deployed. While Docker doesn't have a build framework, you can take advantage of Make to automate the build process across different environments.

Makefiles are text files that provide a simple way to organise code compilation, or in this case Docker image compilation, into named targets. They are used by the make utility in order to execute the required commands to complete an action, such as build a docker images. These Makefiles can contain multiple different targets allowing for a centralised place to store the commands required to build, test, debug and push docker images.

In this scenario we'll explore how to create a Makefile that builds a Docker image.

This was created based on http://blog.benhall.me.uk

As demonstrated in this scenario, Makefiles make it really easy to manage the creation of Docker images. By having a single file you can organise the required commands for creating, debugging and releasing in a single and consistent approach.

NAME = benhall/docker-make-demo
  default: build
      docker build -t $(NAME) .
      docker push $(NAME)
      docker run --rm -it $(NAME) /bin/bash
      docker run --rm $(NAME)
  release: build push

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Docker and Makefiles

Step 1 of 5

Step 1 - Dockerfile

This scenario has a Dockerfile which defines a Docker container to output the current date.

The command docker build -t benhall/docker-make-example . will create a Docker image is a friendly tag benhall/docker-make-example which we can use when starting a container based on the image.

In the next step we'll demostrate how to use this command inside a Makefile.