Docker container for confd configured nginx based on etcd values generated by Registrator. Mainly for CoreOS cluster.
I started with DigitalOcean's Confd and Etcd but I don't like the idea of sidekick instance. I changed sidekick to Registrator and make some changes in Confd configuration.
This docker image made for CoreOs cluster. (Detailed cluster setup soon.) You need working Registrators on every cluster nodes and need to create docker Fleet units named with domain name and instance. For example if you would like to run a Wordpress unit you need to name the docker instance to 'wordpress.example.com'.
docker run --name wordpress.example.com --link some-mysql:mysql -p 80 -d wordpress
Registrator will create a key for 'wordpress.example.com' docker instance at '/services/wordpress/core01.mycluster.com:wordpress.example.com:80' with the IP address of the docker instance and port of the Wordpress. For example: '8.8.8.8:49158'
docker run --name nginx.example.com -p 80:80 -e NGINX_BACKEND_SERVICE=example.com -e NGINX_DEMO_DOMAIN=my-demo-domain.com -e HOST_IP=8.8.8.8 tarhelypark/nginx-confd-etcd
The following environment variables available:
-e NGINX_BACKEND_SERVICE=...
(name of backend service instance, example.com in our example)-e NGINX_DEMO_DOMAIN=...
(demo domain name which also forwarded to backend. If you specify y-demo-domain.com example.y-demo-domain.com will be forwarded to example.com)-e HOST_IP=...
(IP of etcd)-e ETCD_PORT=...
(public port of etcd default: 4001)-e NGINX_WORKER_PROCESSES=...
(number of nginx worker processes, default: cpu x 2)
Following configuration will start Nginx on every machine on the cluster and dinamicaly create configuration and proxy routing to every working Wordpress (or any other) instance.
[Unit]
Description=Nginx proxy and load balancer
After=docker.service
After=etcd.service
[Service]
TimeoutStartSec=0
# Get CoreOS environmental variables
EnvironmentFile=/etc/environment
ExecStartPre=-/usr/bin/docker kill %p.%i
ExecStartPre=-/usr/bin/docker rm %p.%i
ExecStartPre=/usr/bin/docker pull tarhelypark/nginx-confd-etcd
ExecStart=/usr/bin/docker run --name %p.%i -p ${COREOS_PUBLIC_IPV4}:80:80 -e NGINX_BACKEND_SERVICE=%i -e NGINX_DEMO_DOMAIN=tarhelypark.hu -e HOST_IP=${COREOS_PUBLIC_IPV4} tarhelypark/nginx-confd-etcd
ExecStop=/usr/bin/docker stop %p.%i
[X-Fleet]
Global=true