Although I really like the concept of pyourboros, Iām just wondering if its like overly complicating things ā unless you need metrics which Iāll admit is nice if you need such things.
So if using systemd (Iām using Arch host however this would run on Ubuntu/Debian, etc)
docker-compose@.service
docker-compose-reload@.timer
docker-compose-reload@.service
Lets start off with the timer file since this will indicate how often you want to check for updates and restart containers:
[Unit]
Description=Refresh images and update containers
Requires=docker-compose@%i.service
After=docker-compose@%i.service
[Timer]
#OnCalendar=*:0/15
OnCalendar=hourly
[Install]
WantedBy=timers.target
Adjust the OnCalendar variable to your needs.
Ok next the timer file needs to actually reference a file with the same name as the timer with a .service extension. So here is that file:
docker-compose-reload@.service
[Unit]
Description=Refresh images and update containers
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl reload-or-restart docker-compose@%i.service
Ok so this file basically calls the docker-compose@.service file with the reload-or-restart parameter
So the biggest and most important file is the docker-compose@.service. This is where the heavy lifting is done:
[Unit]
Description=Docker Compose %i container starter
After=docker.service network-online.target
Requires=docker.service network-online.target
[Service]
WorkingDirectory=/etc/docker/compose/%i
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/bin/docker system prune
ExecStartPre=/usr/bin/docker-compose down -v
ExecStartPre=/usr/bin/docker-compose rm -fsv
ExecStartPre=/usr/bin/docker-compose pull --quiet
#ExecStartPre=/usr/bin/docker-compose build --compress
ExecStart=/usr/bin/docker-compose up -d
ExecStop=/usr/bin/docker-compose down -v
ExecStopPost=/usr/bin/docker-compose rm -fv
ExecReload=/usr/bin/docker-compose pull --quiet
ExecReload=/usr/bin/docker-compose up -d
[Install]
WantedBy=multi-user.target
You basically see the on restart-reload it does the following two commands:
/usr/bin/docker-compose pull --quiet
/usr/bin/docker-compose up -d
So how do you run all this stuff actually??
Iām running docker-compose.yml. This file is located within the following directory structure
/etc/docker/compose/example.org/docker-compose.yml
Note example.org ā can me any directory
So given this information
systemctl enable docker-compose@example.org.service
systemctl enable docker-compose-reload@example.org.service
systemctl enable docker-compose-reload@example.org.timer
systemctl start docker-compose-reload@example.org.timer
You can check timer list with
systemctl list-timers
You can also check service list with:
systemctl list-units
Seems overly complicated however its really not. By using the @ extension you can actually make these service/timer files modular. Hopefully that helps.