Skip to content

Instantly share code, notes, and snippets.

@kizzx2
Last active July 20, 2026 09:20
Show Gist options
  • Select an option

  • Save kizzx2/782b500a81ce46b889903b1f80353f21 to your computer and use it in GitHub Desktop.

Select an option

Save kizzx2/782b500a81ce46b889903b1f80353f21 to your computer and use it in GitHub Desktop.
Restart a docker container periodically with docker-compose
version: '3'
services:
app:
image: nginx:alpine
ports: ["80:80"]
restart: unless-stopped
restarter:
image: docker:cli
volumes: ["/var/run/docker.sock:/var/run/docker.sock"]
command: ["/bin/sh", "-c", "while true; do sleep 86400; docker restart app_app_1; done"]
restart: unless-stopped
@mrjianlucah

Copy link
Copy Markdown

Thanks a lot!

@nicksterious

Copy link
Copy Markdown

Watch out, some containers don't exit gracefully and will generate core dumps on the host, systemd doesn't delete old files if set to keep the dumps. This will gradually fill up the host drive with dump files until the point where you can't connect and will need to reboot into rescue mode to fix it.

@BobbyGalere

Copy link
Copy Markdown

Hi, thanks for this!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment