Linux β’ Infrastructure & Tunnels
How to Run Docker Compose as a Systemd Service
Running Docker Compose as a systemd service guarantees that your multi-container stack boots automatically when the Docker daemon is ready, and issues `docker compose down` gracefully during host reboot.
/etc/systemd/system/docker-compose-app.service
[Unit]
Description=Docker Compose Multi-Container Stack
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/opt/my-stack
ExecStart=/usr/bin/docker compose up -d --remove-orphans
ExecStop=/usr/bin/docker compose down
TimeoutStartSec=0
[Install]
WantedBy=multi-user.targetCustomize:
User:
WorkingDir:
ExecStart:
Systemctl Lifecycle & Journalctl Monitoring
sudo systemctl daemon-reloadRegister compose servicesudo systemctl enable --now docker-compose-appStart docker compose stack and persist on bootsudo systemctl stop docker-compose-appGracefully run docker compose downLinux & Systemd Production Best Practices
- `RemainAfterExit=yes` is essential for `Type=oneshot` services; it tells systemd to treat the service as active even after the initial `up -d` command completes.
- Ensure `Requires=docker.service` so systemd does not attempt to launch before the Docker daemon socket is initialized.
Frequently Asked Questions About Docker Compose Systemd Service
Frequently Asked Questions
Frequently Asked Questions
Everything you need to know regarding specifications, syntax, and security best practices.
Systemd integrates compose with OS-level shutdown sequences, ensures clean volume flushing, and allows standard `systemctl` monitoring alongside other host services.
Related Linux & Systemd Services
View All ServicesWeb Apps & APIs
How to Create a Systemd Service for Node.js (Express, NestJS, Next.js)
node-app.serviceGuide β
Web Apps & APIs
How to Create a Systemd Service for Python (FastAPI, Flask, Gunicorn, Uvicorn)
python-app.serviceGuide β
Web Apps & APIs
How to Create a Systemd Service for Go (Golang) Compiled Binary
go-service.serviceGuide β
Background Workers & Daemons
How to Run Background Workers (Celery, BullMQ, Sidekiq) with Systemd
queue-worker.serviceGuide β
Timers & Automation
How to Create a Systemd Timer to Replace Cron Jobs
backup-task.serviceGuide β
Infrastructure & Tunnels
How to Keep Reverse SSH Tunnel Persistent with Autossh & Systemd
reverse-tunnel.serviceGuide β