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

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.