Public | Automated Build

Last pushed: 4 days ago
Short Description
Automatically (de)register containers as nodes in Consul.
Full Description


Con-tainer2sul automatically registers and deregisters nodes for any Docker container.

This project is inspired by gliderlabs registrator.

The main difference is that Con-tainer2sul will by default register the containers as nodes. This allows to register a container without having to expose any network service on the host.

<!-- toc -->

<!-- tocstop -->

Running Con-tainer2sul

Using Docker

docker run -d \
  -e c2c_consul__host=localhost \
  -e c2c_consul__port=8500 \
  -v /var/run/docker.sock:/var/run/docker.sock \


Con-tainer2sul uses rc to import its configuration.

The configuration can be overridden using any method supported by rc, for instance using a custom .c2crc file or by defining some environmental variables prefixed by c2c_.


Consul host and port can be configured:


  "consul": {
    "host": "localhost",
    "port": 8500
  "[..]": "[..]"


The docker section of the configuration is given to dockerode constructor.

Please refer to dockerode documentation for supported options.

Default configuration listens to Docker daemon on /var/run/docker.sock unix socket.


  "[..]": "[..]",
  "docker": {
    "socketPath": "/var/run/docker.sock"


Con-tainer2sul uses bunyan. The logger section of the configuraton object is passed to bunyan.createLogger method.

Default configuration outputs logs at info level to stdout.


  "[..]": "[..]",
  "logger": {
    "name": "con-tainer2sul"

Container registration

Con-tainer2sul relies on Docker labels to define the values sent to Consul.

Internally, Con-tainer2sul calls Consul low-level catalog/register and catalog/deregister API endpoints.

IP Address

By default, the registered ip address is the first one found in the NetworkSettings group from docker inspect result.

If the container is running in host network mode, the ip address used is the docker0 one.

The registered ip address can be configured using a consul.ip label.

docker run --rm --name c2c -ti -l consul.ip= alpine ash

will register a service c2c on a node c2c, which will be registered to the ip

By setting the consul.ip label to host, Con-tainer2sul will use docker0 ip address for the node.

Service name

By default, the registered service name is the container name.

The service name can be configured using a consul.service label.

docker run --rm --name c2c -ti -l consul.service=myservice alpine ash

will register a service myservice in Consul.


Tags can be set using a consul.tags label, container the list of tags, comma separated.

docker run --rm --name c2c -ti -l consul.tags=www,api alpine ash

will register a service c2c with www and api tags.


For the time being, Con-tainer2sul support registering only one port.

Port can be set using a consul.port label.

docker run --rm --name c2c -ti -l consul.port=80 alpine ash

will register a service c2c on port 80.

Key/Value pairs

Each container can be attached some key/value pairs, using the consul.kv.<KEY> template.

docker run --rm --name c2c -ti -l -l alpine ash

will register a service c2c and create 2 key/value pairs under the /services/c2c/ tree.2 key/value pairs under the /services/c2c/ tree.

Skipping registration

You can tell Con-tainer2sul to not register the container by using a container.skip label, set to anything else than false.

docker run --rm --name c2c -ti -l consul.skip=true ash

will not register any node or service in Consul.

Docker Pull Command
Source Repository