Why?
I created this proxy for 2 reasons.
- Local development with more than one container that needs to run on a single HTTP port (eg. 80)
- Load balance across multiple hosts with containers ready to serve a single site. Powered by Docker Swarm.
Example
I have the containers:
-
container1
- Port 80 exposed
- Environment variable DOMAIN set to www.example.com
-
container2
- Port 80 exposed
- Environment variable DOMAIN set to www.example.com
-
container3
- Port 8983 exposed
- Environment variable DOMAIN set to www.foobar.com
-
container4
- Port 80 exposed
-
container5
- Environment variable DOMAIN set to www.baz.com
This proxy will setup the following routes:
- A "random" load balanced connection between container1 and container2
- A proxy connection to container3
- No proxy connection will be setup for container4 given it doesn't have a DOMAIN environment variable set.
- No proxy connection will be setup for container5 given it doesn't have a Port exposedt.
How to run
Build the binary with
$ go build marco.go
Run the binary with
$ sudo ./marco
Run with all the args
$ sudo ./marco -bind=8080 -ports=80,8983,8080 -endpoint=tcp://localhost:2375
- bind - Server traffic through the following port.
- ports - The Docker exposed ports that this proxy can use (in order).
- endpoint - Connection to the Docker daemon.
Run inside a Docker container
$ docker pull nickschuch/marco
$ docker run -d -p 0.0.0.0:80:80 -v /var/run/docker.sock:/var/run/docker.sock nickschuch/marco
Demo
I will post a video very soon...
Roadmap
- Http auth (maybe)
- Logging
- Error handling