Docker Community Forums

Share and learn in the Docker community.

Coordination between docker-compose services, is this a good idea?

I have several use cases where an action in one docker-compose service should trigger some activity in another.

  • certbot renewal in a certbot container should trigger nginx reload in a nginx container
  • OSM import in an osm2pgsql container should trigger re-render in a mapnik/tilestache container

I found an easy way to do this, using netcat

For example in the nginx docker-compose service could start a netcat in listen mode like this
nc -p 23 -lk -e /usr/sbin/nginx-reload &

Where nginx-reload is

#!/bin/sh
/usr/sbin/nginx -s reload

Then the certbot docker-compose service can trigger nginx reload like this
nc -z webserver 23

Of course port 23 will not be exposed outside the docker-compose containers. Any other port can be used.

I wonder if there exists a docker-compose feature that I am reinventing here? Or maybe there are easier ways to do this? Thanks!

You could use a shared process namespace and use kill -s HUP 1 to reload nginx. Example:

services:
  nginx:
    # ...
  certbot:
    # ...
    pid: service:nginx

This way certbot would use the same process namespace as nginx which means the process id of nginx in the certbot container would be 1. This is why you could use kill -s HUP 1 from the certbot container to reload nginx.

NginX signals: Controlling nginx

Other solution could be to mount the docker socket into the certbot container and use the docker api to reload the container.

Great input, thanks!
So I was reinventing a docker feature :slight_smile: