Manage a shit-ton of smaller docker-compose files
I have multiple servers running in my home all doing their own thing for various people in our household. I’m not gonna lie, most of them run off a giant docker-compose file. But on some “play” servers I experiment more and get to try different organization strategies.
This is gonna seem like a no-brainer, here goes:
One master yml, bunches of includes.
include: - path: 'actual/docker-compose.yml' - path: 'codeserver/docker-compose.yml' - path: 'glance/docker-compose.yml' - path: 'homepage/docker-compose.yml' - path: 'tududi/docker-compose.yml' - path: 'vogon/docker-compose.yml'And then my docker-apps directroy structure looks like this:
├── actual│ ├── data│ └── docker-compose.yml├── codeserver│ ├── config│ └── docker-compose.yml├── glance│ ├── config│ └── docker-compose.yml├── homepage│ ├── config│ └── docker-compose.yml├── tududi│ ├── config│ └── docker-compose.yml├── vogon│ ├── config│ └── docker-compose.yml├── .env├── docker-compose.yml└── recompose.shExample of a sub-service glance/docker-compose.yml file:
services: glance: container_name: glance image: glanceapp/glance restart: unless-stopped volumes: - ${APPDATADIR}/glance/config:/app/config ports: - 9000:8080I use each directory to house any volumes, config data, etc. for that service. Until it graduates to family-critical I’m okay with wiping this out occasionally.
And they all share the same .env file:
COMPOSE_HTTP_TIMEOUT='60'APPDATADIR='/home/joe/docker-apps'GID='******'HOSTNAME='******'PGID='******'PUID='******'TZ='******'And when I want to add or remove a service, I just edit the master docker-compose.yml file and restart the services.
I also have a recompose.sh script that I can run to completely rebuild all the services.
#!/bin/bash
docker compose stopdocker compose rmdocker compose pulldocker compose up -dAnd I can run it with:
./recompose.sh