Subscribing to Consul Key-Value

I’m trying to use Consul’s Key-Value API to pass a JSON configuration to an app running in one of my containers. It works great, but the API does not provide any pub-sub functionality (just read/write/delete) for a key.

So far, I managed to artificially compensate by using the Watch feature to restart the container whenever the key changes, but that leaves me with the need to

  • Want to use volumes in my running Docker container
  • How to change a docker repository to automated build?
  • Can not start Docker 1.9.1
  • Correlate a gitlab ci run to its runner
  • How do docker containers resolve hostname of other docker containers running on the same machine?
  • make test failed when compile Node.js 4.0.0 source code in docker container
    1. Externally configure Consul (either load a new configuration, or use the CLI, to specify a key to watch, and a shell script to run)
    2. Restart my app in mid-run – a good way to potentially lose data.

    Is there any programatic way (other than polling every x seconds) to get notified of a key change in Consul, or should I just back away from this solution, and move to Redis?

  • Limitations in Mesos and Marathon Regarding Docker
  • docker swarm service how to specify a delay time in restart policy?
  • restart mongodb docker with auth
  • Docker: Dockerizing apache virtual hosts
  • Unable to start Docker Container in Bluemix
  • when pushing docker image to private docker registry, having trouble marking it 'public' via my script (but can do via web ui)
  • One Solution collect form web for “Subscribing to Consul Key-Value”

    After a quick look at consul’s sources, it seems that the “watch” is a simple periodic pull. You could implement something similar in your code to achieve this.

    Periodic run of the watcher: https://github.com/hashicorp/consul/blob/master/watch/plan.go#L46

    KeyWatch Handler: https://github.com/hashicorp/consul/blob/master/watch/funcs.go#L29

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.