Compose Service Pattern ๐
Overview ๐
This pattern describes how to structure and manage services running with docker-compose on Debian stable systems.
Goals ๐ฏ
- Consistent service deployment structure
- Predictable locations and configurations
- Easy backup and maintenance
- Secure default settings
Directory Structure ๐
/srv/{hostname}/ # Root directory for the serviceโโโ compose.yaml # Main compose file (new standard name)โโโ compose.override.yaml # Proxy network integrationโโโ .env # Environment variablesโโโ .gitignore # Git ignore fileโโโ SERVICE.md # Service documentation
Base Requirements ๐ ๏ธ
- Debian Stable (current: Bookworm)
- docker.io and docker-compose from debian-stable repository with apt
- Regular system updates via unattended-upgrades
Manual Service Setup ๐
System Packages
sudo apt updatesudo apt install docker.io docker-compose-plugin apparmor
Service Directory
mkdir /srv/{hostname}cd /srv/hostname}
Base Compose File
compose.yaml:
version: '3.9'
services: app: image: application:version restart: unless-stopped environment: - TZ=UTC env_file: .env volumes: - ./config:/config:ro - ./data:/data
networks: default: driver: bridge
Proxy Integration
compose.override.yaml:
version: '3.9'
networks: proxy: external: true
services: app: networks: - proxy - default
Git Configuration
If your service is stored in a Git repo, you should ignore the compose.override.yaml and SERVICE.md. .gitignore:
compose.override.yamlSERVICE.md
Security Practices ๐
- Use specific version tags
- Restrict directory permissions
- Read-only mounts where possible
- Limit network exposure
- Run services as non-root user
- Only expose necessary services to proxy network
Operations ๐
Start/Stop
cd /srv/{hostname}docker-compose up -d # Startdocker-compose down # Stop
Updates
cd /srv/{hostname}docker-compose pulldocker-compose up -d
Anti-patterns โ ๏ธ
- Using latest tag
- Storing secrets in compose.yaml
- Direct modification of container data
- Exposing services to proxy network unnecessarily
Tips ๐ก
- Document service specifics in SERVICE.md
- Use .env-File for configuration
- Enable health checks
- Keep proxy network configuration separate in override file
- On Debian Stable the docker-compose command is based on the old Python compose implementation. Because of this you need to write
docker-compose
and notdocker compose