Giter Club home page Giter Club logo

docker-gen's Introduction

docker-gen with dynamic container names support

This is an enhancement to the docker-gen image that adds a script that can send a SIGHUP signal to a container through the use of a label.

The problem

The usual way of using docker-gen in conjunction with docker-letsencrypt-nginx-proxy-companion using the separate container method, is as follows (as per the docs):

$ docker run -d \
    --name nginx-gen \
    --volumes-from nginx \
    -v /path/to/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro \
    -v /var/run/docker.sock:/tmp/docker.sock:ro \
    jwilder/docker-gen \
    -notify-sighup nginx -watch -only-exposed -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf

However, within a Docker Cloud or Swarm Mode based environment we cannot use -notify-sighup nginx due to the fact that the container names (on the actual nodes) do not match their service names. The result is that the nginx container (Service) never get's reloaded to take advantage of the generated Nginx configuration.

The solution

Add a label to the container you want to reload, with value true. Then, use the bundled docker-label-sighup script, with the label name as an argument. For example:

services:
  nginx:
    image: nginx:alpine
    ports:
      - 80:80
      - 433:433
    volumes:
      - nginx:/etc/nginx/conf.d
      - nginx:/etc/nginx/certs
    labels:
      - com.example.nginx_proxy=true

  dockergen:
    image: helder/docker-gen:latest
    command: -notify "docker-label-sighup com.example.nginx_proxy" -watch -only-exposed -wait 10s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
    volumes:
      - nginx:/etc/nginx/conf.d
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl

volumes:
  nginx:

Note the use of -notify instead of using -notify-sighup to redeploy the service using the bundled script.

docker-gen's People

Watchers

 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.