Public | Automated Build

Last pushed: 2 years ago
Short Description
Short description is empty for this repo.
Full Description

KV_CONSUL plugin for docker-plugins

This is a plugin for progrium/docker-plugins that sets consul keys when a docker container is started.

This plugin is very useful when used with registrator and consul-template or similar tools.

Installing

docker run -it --rm \
   -e DEBUG=1 \
   -e "INSTALL=https://github.com/bryanlarsen/docker-plugin-kv-consul" \
   -e "ENABLE=docker-plugin-kv-consul" \
   -e "KV_CONSUL_IP=consul.service.consul" \
   --hostname="$(hostname)" \
   -v /var/run/docker.sock:/var/run/docker.sock \
   progrium/plugins

or

docker run -it --rm \
   -e "KV_CONSUL_IP=consul.service.consul" \
   --hostname="$(hostname)" \
   -v /var/run/docker.sock:/var/run/docker.sock \
   bryanlarsen/kv-consul

Configuring

  • KV_CONSUL_IP: (default 127.0.0.1)
  • KV_CONSUL_PORT: (default 8500)
  • KV_CONSUL_PREFIX: (default "") Sets the prefix or namespace for all keys.
  • KV_CONSUL_URL: (default http://${KV_CONSUL_IP}:${KV_CONSUL_PORT}/v1/kv/${KV_CONSUL_PREFIX})

Usage

To use this plugin, set environment variables on your containers. They may be either set in your Dockerfile or set during docker run.

KV_SET:

Prefix the environment variable with "KV_SET:" to unconditionally set a key.

docker run -e "KV_SET:foo=1" myapp

Sets a key called foo to 1.

Add a "?" suffix to conditionally set the key.

docker run -e "KV_SET:bar?=1" myapp

Sets a key called bar to 2, unless bar already has a value in Consul.

Substitution

You can substitute information from the container or image into either the key or the value by using #<keyword># syntax

docker run -e "KV_SET:images/#<IMAGE_NAME>#=#<CONTAINER_NAME>#" myapp
  • IMAGE_ID
  • IMAGE_NAME
  • CONTAINER_ID
  • CONTAINER_NAME
  • IP_ADDRESS
  • SERVICE_ID: the service-id that is generated by registrator
  • SERVICE_NAME: the service-name that is generated by registrator
  • HOSTNAME: this is the hostname where the kv-consul plugin is running, not the hostname inside the container. This behaviour is consistent with registrator.
  • SERVICE_<port>_NAME: the service-name that is generated by registrator for container port <port>
  • SERVICE_<port>_ID: the service-id that is generated by registrator for container port <port>
  • HOST_<port>_PORT: the port mapped on the host from container port <port>

Substituting jq expressions

You can also substitute an arbitrary jq expression.

docker run -e 'KV_SET:public=#jq<.Volumes["/app/public"]>#' myapp

You can develop and test your jq expressions by using docker inspect on the container.

docker inspect happy_euclid | jq '.[0].Volumes["/app/public"]'

If you're substituting into the key, make sure that your jq expression doesn't contain any spaces.

Running the tests

This plugin includes unit tests. To run them:

./start || echo 'tests failed'
Docker Pull Command
Owner
bryanlarsen