Coder Social home page Coder Social logo

docker-irestarter's Introduction

docker-irestarter

Restart a docker container when a file is modified.

How

This project combines inotifywait from inotify-tools with Docker to watch for a modification to a file and restart containers with a specific label.

For example, this image could be used in a docker-compose file to restart a container upon an update to an SSL certificate file, where the service is unable to handle this itself. In this case, you would configure the environment variable to monitor the certificate file.

Example compose file

Read on, or view an example project.

This example has been created based upon the docker compose CLI v2.

Set the file to monitor for changes as an environment variable.

This can also be set in a .env file in the same directory as the compose file.

Note: Environment variables set with export or another method take precedence over .env. Ensure to unset MONITOR_FILE if issues with .env are experienced.

You should always ensure the irestarter container is running following a docker-compose up.

Alternatively, you can individually replace ${MONITOR_FILE} in the compose file with suitable values.

MONITOR_FILE=/file/to/monitor.txt

This snippet can be inserted into an existing compose file with minimal changes.

version: "3"
services:
  docker-irestarter:
    image: ghcr.io/zetifi/docker-irestarter:1
    restart: always
    volumes:
      - ${MONITOR_FILE}:${MONITOR_FILE}
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - MONITOR_FILE=${MONITOR_FILE}

  example-service:
    ...
    labels:
      - "docker-irestarter"

Send a Linux Signal instead of container restart

Instead of restarting the container, it's possible to send a signal to a container. Refer to the signal(7) man-page for a list of standard Linux signals.

Note the SIGHUP signal passsed as an environment variable to the docker-irestarter container.

version: "3"
services:
  docker-irestarter:
    image: ghcr.io/zetifi/docker-irestarter:1
    restart: always
    volumes:
      - ${MONITOR_FILE}:${MONITOR_FILE}
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - MONITOR_FILE=${MONITOR_FILE}
      - SIGNAL=SIGHUP

  example-service:
    ...
    labels:
      - "docker-irestarter"

docker-irestarter's People

Contributors

connorhsm avatar contraxx avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.