top of page
Search
Writer's picturechourmovs vs

Docker compose: programmatically restart your containers or stacks from docker.

Docker may make our lives easier when it comes to deploying and maintaining applications on your different platforms, providing a good level of optimization and resource management, but it does not erase the flaws designs of certain software (particularly servers) that can get "lost" in the management of memory, CPU or network resources until they crash or no longer work, especially after several days of operation.

In this case, it is well known to somewhat experienced IT specialists, a good "reboot" of the machine is often essential.


This is exactly what the following code does, presented here in its docker-compose version


services:
  gluetun:
    image: qmcgaw/gluetun:latest
    container_name: Gluetun
....etc

  mldonkey:
    image: logicwar/mldonkey:latest
    container_name: Mldonkey

....etc

  restarter:
    image: docker:cli
    volumes: ["/var/run/docker.sock:/var/run/docker.sock"]
    command: ["/bin/sh", "-c", "while true; do sleep 36000; docker restart Gluetun && docker restart Mldonkey;done"]
    restart: unless-stopped
volumes:
  gluetun:

We can see that compose creates a "restarter" container which connects to the Docker daemon of the host machine via its socket, thus allowing bash commands to be executed on the latter.


Here the bash command in question executes a classic "while true do sleep" for 10 hours before restarting the two "dockerized" applications Gluetun and Mldonkey.


It works... and opens many perspectives in terms of automating tasks on somewhat "closed" and poorly documented systems, via docker and a bit of bash.


Hope this has been helpful.


93 views0 comments

Commenti

Valutazione 0 stelle su 5.
Non ci sono ancora valutazioni

Aggiungi una valutazione
bottom of page