Docker compose as a systemd unit ================================ Create file `/etc/systemd/system/docker-compose@.service` ```ini [Unit] Description=%i service with docker compose Requires=docker.service After=docker.service [Service] Restart=always WorkingDirectory=/apps/%i # Remove old containers, images and volumes ExecStartPre=/usr/local/bin/docker-compose down # Compose up ExecStart=/usr/local/bin/docker-compose up # Compose down, remove containers and volumes ExecStop=/usr/local/bin/docker-compose down [Install] WantedBy=multi-user.target ``` Place your `docker-compose.yml` into `/apps/myservice` and call ``` systemctl start docker-compose@myservice ``` Docker cleanup timer with system ================================ Create `/etc/systemd/system/docker-cleanup.timer` with this content: ```ini [Unit] Description=Docker cleanup timer [Timer] OnUnitInactiveSec=12h [Install] WantedBy=timers.target ``` And service file `/etc/systemd/system/docker-cleanup.service`: ```ini [Unit] Description=Docker cleanup Requires=docker.service After=docker.service [Service] Type=oneshot WorkingDirectory=/tmp User=root Group=root ExecStart=/usr/bin/docker system prune -f [Install] WantedBy=multi-user.target ``` run `systemctl enable docker-cleanup.timer` for enabling the timer