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
- In the root of your Compose project create a file named
Makefile. - Add an optional
.envfile next to theMakefileif you need environment variables. The Makefile includes.envso variables defined there will be available. - 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.envfile exists it is included bymakeso you can store configuration there (for example overrides or commonly used variables).COMPOSE— defaults todocker compose -f docker-compose.yml. You can override this on the command line if you preferpodmanor 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 runspullfollowed byup -d.make fixnet— Recreates the named Docker network used by the stack (hereskynetlan). 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— Runsdocker image prune -fto remove unused images.
Examples
- Start services:
- Update images and restart:
- Recreate the compose network (fix connectivity problems):
- Run with an alternative compose command (example: Podman):
Tips and safety
makeruns theinclude .envdirective even if.envis 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
fixnettarget attempts to remove the network; removal may fail if containers are still attached — ensure the stack is down before removing networks. docker image prune -fincleanwill delete dangling images. Remove-fto prompt before deleting.