Skip to content

Makefile for Docker Compose

This page documents the Makefile used to manage the local Docker Compose stack. It explains how to create the Makefile, what each target does, and how to use it.

Create the Makefile

  1. In the root of your Compose project create a file named Makefile.
  2. Add an optional .env file next to the Makefile if you need environment variables. The Makefile includes .env so variables defined there will be available.
  3. Use the following contents in the Makefile:
include .env

COMPOSE?=docker compose -f docker-compose.yml

install:
    $(COMPOSE) up -d

update:
    $(COMPOSE) pull
    $(COMPOSE) up -d

fixnet:
    $(COMPOSE) down
    docker network rm skynetlan || true
    docker network create skynetlan
    $(COMPOSE) up -d

clean:
    docker image prune -f

Notes about the Makefile

  • include .env — if a .env file exists it is included by make so you can store configuration there (for example overrides or commonly used variables).
  • COMPOSE — defaults to docker compose -f docker-compose.yml. You can override this on the command line if you prefer podman or a different compose command: make COMPOSE="podman compose -f docker-compose.yml" install.

Targets and usage

  • make install — Starts the Compose stack in detached mode (up -d). Use this to bring services up.
  • make update — Pulls newer images then restarts the stack. This runs pull followed by up -d.
  • make fixnet — Recreates the named Docker network used by the stack (here skynetlan). It stops the stack, removes the network, recreates it, and brings the stack back up. This is useful when the Compose network gets into a bad state.
  • make clean — Runs docker image prune -f to remove unused images.

Examples

  • Start services:
make install
  • Update images and restart:
make update
  • Recreate the compose network (fix connectivity problems):
make fixnet
  • Run with an alternative compose command (example: Podman):
make COMPOSE="podman compose -f docker-compose.yml" install

Tips and safety

  • make runs the include .env directive even if .env is missing; if you want to require it, create one. The Makefile as written will error if include can't find the file; you can make inclusion optional by using -include .env.
  • The fixnet target attempts to remove the network; removal may fail if containers are still attached — ensure the stack is down before removing networks.
  • docker image prune -f in clean will delete dangling images. Remove -f to prompt before deleting.