Hi @mvandenabeele,
We did a few tests around the topic to check how one could better proceed. On the example @lucas_a.tx posted here, it will indeed have this behavior on a shutdown as the unless-stopped exists. We then created a systemd service structure to stop every running container from running on the module once a shutdown or a reboot is asked, for instance by running sudo reboot
or sudo shutdown
.
This way, the containers will not try to restart all at once on startup and will follow the exact startup route proposed on the docker-compose according to the depends_on condition.
The structure could be something as follows:
- Create one service such as the one bellow on /etc/systemd/system and activate it using
sudo systemctl enable my_service.service
[Unit]
Description=Forcing Docker Stop on shutdown
DefaultDependencies=no
Before=shutdown.target poweroff.target halt.target reboot.target
Requires=poweroff.target
[Service]
Type=oneshot
ExecStart=/home/torizon/compose_kill.sh
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
- Create a shell script that stops all containers, and save it in the path you mentioned on the service, such as:
#!/bin/sh
echo "Killing docker processes"
docker stop $(docker ps -a -q)
echo "Killed"
Please note, however, that if the power is cut, this sample service may not work, and then you may arrive again on a Out of Memory Condition. Some adaptations may be needed according to your use case.
Another possibility would to simply remove the restart condition on the docker compose and set up another service that monitors the health of your containers.
We are trying other things in the meantime to check for alternative solutions such as limiting memory available while starting the containers.