Add dependencies between containers¶
A container that needs another one, such as an app and its database, declares that in its [Unit] section.
systemd then starts the other container too, and in the right order.
The examples below make the container app depend on db.
Declare the dependency¶
Name the other container's quadlet file in Wants= and After=:
Quadlet translates db.container into the service name db.service.
Wants=startsdbwheneverappstarts, for example when you startappby hand.After=makesappwait untildb's service has started, and stopsappbeforedbon shutdown.
After= waits for the container to start, not for the database to accept connections, so app should retry its first connection.
To make After= wait until db is ready, give db a health check and Notify=healthy (see Wait until a container is healthy).
syslet doesn't check the name.
With a misspelled one, systemd ignores the dependency and starts app on its own.
Avoid Requires=¶
Requires=, BindsTo= and PartOf= make systemd stop app whenever db stops.
When a change restarts db, syslet stops it and starts it again, but it doesn't start app, since app was running when the plan was made.
app stays down until the next apply.
Wants= doesn't pass the stop on, so app keeps running while db restarts.
A oneshot job is the exception, see Run a oneshot job.
Preview and apply¶
The new [Unit] options change app's unit, so syslet restarts it.