• Stars
    star
    464
  • Rank 94,450 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Magic proxy for internal services

Connectable

Docker Hub IRC Channel

A smart Docker proxy that lets your containers connect to other containers via service discovery without being service discovery aware.

Getting Connectable

You can get the Connectable micro container from the Docker Hub.

$ docker pull gliderlabs/connectable

Using Connectable

Basic overview is:

  1. Run a service registry like Consul, perhaps with Registrator
  2. Start a Connectable container on each host
  3. Expose Connectable to your containers, using links or Resolvable (experimental)
  4. Run containers with labels defining what they need to connect to with what ports
  5. Have software in those containers connect via those ports on localhost

Starting Connectable

Once you have a service registry set up, you point Connectable to it when you launch it. You also need to mount the Docker socket. Here is an example using the local Consul agent, assuming you're running Resolvable:

$ docker run -d --name connectable \
		-v /var/run/docker.sock:/var/run/docker.sock \
		gliderlabs/connectable:latest

With Resolvable running, it will have access to Consul DNS. It will be able to resolve any connections using DNS names.

Start containers that use Connectable

All you have to do is specify a port to use and what you'd like to connect to as a label. For example:

connect.6000=redis.service.consul

With this label set, you can connect to Redis on localhost:6000. You can also specify multiple services:

$ docker run -d --name myservice \
		-l connect.6000=redis.service.consul \
		-l connect.3306=master.mysql.service.consul \
		example/myservice

Load Balancing

Connectable acts as a load balancer across instance of services it finds. It shuffles them randomly on new connections. Although this seems less predictable, it ensures even balancing cluster-wide.

Connectable is a reverse proxy and balancer, but it is not recommended to be used as your public facing balancer. Instead, use a more configurable balancer like haproxy or Nginx. Use Connectable for internal service-to-service connections. For example, you could use Connectable with Nginx to simplify your Nginx container setup.

Health Checking

Currently Connectable does not have native health checking integration. For now, Connectable defers to the registry to return healthy services. For example, this is how Consul DNS works. Otherwise, when Connectable tries to connect to an endpoint and is unable to connect, it will try the next one transparently until all services have been tried. This covers some but not all "unhealthy" service cases.

Future modules may add support for integration with health checking mechanisms.

Overhead

Like all proxies, you incur overhead to your connections. Connectable is roughly comparable but slightly slower than Nginx. Not by much. Here is some data collected using HTTP requests via ApacheBench using -n 200 -c 20:

nginx:

    Requests per second:    754.53 [#/sec] (mean)
    Time per request:       26.507 [ms] (mean)
    Time per request:       1.325 [ms] (mean, across all concurrent requests)

connectable:

    Requests per second:    606.32 [#/sec] (mean)
    Time per request:       32.986 [ms] (mean)
    Time per request:       1.649 [ms] (mean, across all concurrent requests)

Memory overhead is also roughly comparable per connection. Added network latency is near zero since it's running on the same host as clients. Keep in mind, Connectable is designed to run on each host for best performance and to avoid SPOF.

Although Connectable is Good Enough for most cases, if the overhead is a deal breaker for a particular case, don't use it in that particular case. Alternatives include working with service registries directly, just using DNS discovery with known ports, setting up a full SDN, etc.

Modules

Todo

Why not just DNS?

If you're using Consul DNS, SkyDNS, et al, you may wonder why Connectable is necessary. The answer is ports. Most software is not designed for dynamic ports. Most software can only resolve hostnames to IPs. You have to hard configure the port used.

If you are able to run all containers publishing exposed ports on known ports (-p 80:80), you might not need Connectable. If you have a fancy SDN solution that makes private container IPs publicly addressable and they use known ports, you don't need Connectable.

However, if you run containers with non-conventional ports, or don't have control over published ports, or just want to not care and wish it were magically taken care of ... that's what Connectable is for.

Connectable when combined with Registrator lets you run containers with -P and not care about what port they publish as.

Also, DNS may not randomize results, effectively balancing services. Connectable ensures internal load balancing.

Notes

moby/moby#7468 moby/moby#7467

Sponsor and Thanks

Connectable is sponsored by Weave. The original ambassadord proof of concept was made possible thanks to DigitalOcean. Also thanks to Jรฉrรดme Petazzoni for helping with the iptables bits that make this magical.

License

MIT

More Repositories

1

docker-alpine

Alpine Linux Docker image. Win at minimalism!
Shell
5,699
star
2

registrator

Service registry bridge for Docker with pluggable adapters
Go
4,661
star
3

logspout

Log routing for Docker container logs
Go
4,645
star
4

ssh

Easy SSH servers in Golang
Go
3,634
star
5

herokuish

Utility for emulating Heroku build and runtime tasks in containers
Shell
1,434
star
6

docker-consul

Dockerized Consul
Shell
1,070
star
7

sigil

Standalone string interpolator and template processor
Go
413
star
8

resolvable

Host-level DNS gateway for Docker
Go
314
star
9

sshfront

Programmable SSH frontend
Go
301
star
10

com

Library for structuring Golang applications into components
Go
90
star
11

hostlocal

Host-level localhost for containers
69
star
12

hostctl

Opinionated CLI utility for easily provisioning cloud VMs
Go
35
star
13

stdcom

Re-usable Go components and micro-frameworks
Go
33
star
14

glidergun

Shell
31
star
15

cmd

Go
28
star
16

cellstack

DEPRECATED
Shell
23
star
17

pagebuilder

HTML
16
star
18

slack

JavaScript
15
star
19

comlab

Glider Labs app framework and development utility
Go
15
star
20

python-runtime

DEPRECATED
Shell
13
star
21

dockerbox

Container that runs a Docker daemon configured for running user code.
Go
13
star
22

infra.gl

DEPRECATED
HCL
12
star
23

kube-certdaemon

Simple daemon to fetch and refresh Let's Encrypt certs stored in k8s secrets
Go
7
star
24

glu

Glider Labs Utility, DEPRECATED
Go
7
star
25

gliderlabs.github.io

JavaScript
4
star
26

glidergun-rack

Shell
4
star
27

exp

Experimental projects and PoCs
Go
2
star
28

pkg

Go
2
star
29

ci

CI environment for Glider Labs projects
1
star
30

bigtoy

Glider Labs Semantic UI theme
1
star
31

gliderlabs.io

JavaScript
1
star
32

dns

HCL
1
star