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
  
  build:
      docker build -t $(NAME) .
  
  push:
      docker push $(NAME)
  
  debug:
      docker run --rm -it $(NAME) /bin/bash
  
  run:
      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.

Makefile