A Docker Dive tool can be used to explore Docker image, its layers and contents to find a way to reduce size of the image.

Makefile recipe:

docker-efficiency:
	docker run \
		--rm \
		-it \
		-v /var/run/docker.sock:/var/run/docker.sock \
		--mount type=bind,source=${shell pwd}/.dive.yaml,target=/.dive-ci \
		wagoodman/dive:v0.10.0 \
		${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} --ci-config /.dive-ci

Content of the .dive.yaml file:

rules:
  # If the efficiency is measured below X%, mark as failed.
  # Expressed as a ratio between 0-1.
  lowestEfficiency: 0.95
 
  # If the amount of wasted space is at least X or larger than X, mark as failed.
  # Expressed in B, KB, MB, and GB.
  highestWastedBytes: 75MB
 
  # If the amount of wasted space makes up for X% or more of the image, mark as failed.
  # Note: the base image layer is NOT included in the total image size.
  # Expressed as a ratio between 0-1; fails if the threshold is met or crossed.
  highestUserWastedPercent: 0.20