0

I want to run some containers via systemd and each one has an an associated compose file so that it should be possible to write just one systemd unit file and specify the compose file as the instance name. Thus, the unit file will contain something like:

ExecStart=/usr/local/bin/docker-compose -f %i.yaml up 

However, this neat scheme is spoilt by some dependencies betweeen the containers. Normally one would deal with such dependencies with a Requires declaration in the unit file but in this situation there is only one unit file. Is it possible to set up the dependencies outside any unit file, and if so, how?

Example: n-tier-app.yaml depends on basic-services.yaml

2
  • What's the point of rebuilding docker compose functionality in systemd? Commented Jan 28 at 13:36
  • Thanks Grawity for the answer. We eventually re-implemented all our containers as Proxmox LXC guests, thus circumventing the matter. @Gerald -- we want to establish ordering amongst systemd units, but without touching the unit file itself. Commented Mar 7 at 4:10

1 Answer 1

0

Define the dependencies in per-instance <unit>.d/ drop-in files. For example, if you have a template [email protected] you can further configure individual instances through [email protected]/foo.conf and [email protected]/deps.conf.

There is no way to define dependencies with ordering outside of any unit file, but the requirement to define them outside of any unit file is superfluous given the stated goal of creating dependencies between instances of the same unit.

Dependencies without ordering can be defined in a similar way to the above, by symlinking some unit to <unit>.requires/ or <unit>.wants/. This works with templates because only the symlink name matters; it can point to a nonexistent file (e.g. to ../[email protected]) as systemd will manually resolve its basename to a unit. It is however limited to Wants/Requires and therefore usually only useful for adding dependencies from a .target unit – which has a special case of implicitly adding After to any dependency – therefore <unit>.d/*.conf is preferred for all other cases.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.