How to run docker-compose up -d at system start up?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Running docker compose up -d automatically at boot is a common requirement for self-hosted services and internal tools. The reliable way to do this on Linux is a systemd unit that starts after Docker and network availability. You can also use cron @reboot, but systemd gives better ordering, restart behavior, and observability.
Use a Dedicated systemd Service
A systemd service lets you define startup dependencies, working directory, and stop behavior in one place. This is the preferred approach for long-term maintenance.
Create a unit file:
Example unit:
Then enable and start:
This ensures your stack starts at boot and can be managed through normal service commands.
Choose the Correct Compose Command Path
Many failures come from mismatched binary paths. Modern setups often use docker compose plugin, while older setups use standalone docker-compose.
Check what exists:
If your server only has the standalone binary, unit file commands should use /usr/local/bin/docker-compose or whichever path is actually installed.
A safe check before enabling startup automation is to run the exact startup command manually from the same directory:
If this command fails manually, the unit will fail too.
Rootless and Per-User Service Option
If Docker runs rootless under a specific user, use a user-level service instead of system-wide service.
Create user unit:
User unit example:
Enable for user session:
If you need this to run without active login, enable user lingering:
cron @reboot as a Minimal Alternative
cron can run a command at startup with less setup, but it is weaker for dependency management and logs.
Add:
This can work for simple setups. The tradeoff is poorer lifecycle control compared with systemd.
Validation and Troubleshooting Workflow
After configuration, test reboot behavior explicitly.
After host returns:
If service failed, inspect logs:
Useful diagnostics:
- verify
WorkingDirectorycontains the compose file - verify compose file references images and volumes that exist
- verify Docker daemon is healthy at startup
- verify network dependencies are available if services require external systems
Common Pitfalls
A common pitfall is using the wrong compose binary path. Service starts but command fails immediately.
Another issue is missing WorkingDirectory, which causes compose to run from root directory and fail to find docker-compose.yml.
Many teams also omit After=docker.service, leading to race conditions where service runs before Docker is ready.
Using cron @reboot without log redirection is another frequent problem. Failures then look silent because output is discarded.
Finally, avoid running destructive ExecStop behavior for stacks that should persist across transient service restarts unless that shutdown is truly desired.
Summary
systemdis the best default for running Compose at startup.- Define startup ordering with Docker and network targets.
- Validate binary path and working directory before enabling boot automation.
- Use user-level services for rootless Docker workflows.
- Keep a clear troubleshooting path with
journalctland post-reboot checks.

