Thanks for your input. I've had a play with envconsul and if I understand correctly it's the same mechanism as consul-template, but one that manipulates env vars instead of outputting a template.For now, as my application was not previously in Docker, it wasn't built to pick up everything from the environment. That can (probably should) be changed, although it's not always easy with legacy apps. At the very least, I could have a /start.sh that generates the necessary config file from the env vars.
For now, as my application was not previously in Docker, it wasn't built to pick up everything from the environment. That can (probably should) be changed, although it's not always easy with legacy apps. At the very least, I could have a /start.sh that generates the necessary config file from the env vars.This is what we do, and I recommend it. You might also want to scrub sensitive environment variables in your start.sh script before exec'ing the application.
In general, I recommend treating Docker like a package manager, and using host networking whenever possible. Once you do that, the remaining complication becomes moot, and you can treat your Docker app like any other program, although started with a different command line. If you really need to bind to the same port in different containers, bind the application to an aliased IP interface if you can.
Whats the legacy app?
FROM ubuntu
RUN apt-get update \ && apt-get -yq install \ curl \ unzip \ jq \ && rm -rf /var/lib/apt/lists/*
RUN cd /tmp \ && curl -L -O https://github.com/hashicorp/envconsul/releases/download/v0.5.0/envconsul_0.5.0_linux_amd64.tar.gz \ && tar xfz envconsul_0.5.0_linux_amd64.tar.gz \ && mv envconsul_0.5.0_linux_amd64/envconsul /usr/local/bin \ && rm /tmp/envconsul_0.5.0_linux_amd64.tar.gz \ && rmdir /tmp/envconsul_0.5.0_linux_amd64
ADD https://dl.bintray.com/mitchellh/consul/0.5.2_linux_amd64.zip /tmp/consul.zipRUN cd /bin && unzip /tmp/consul.zip && chmod +x /bin/consul && rm /tmp/consul.zip
consul: image: test/ubuntu command: consul agent -join consul.aws -data-dir /tmp net: host
ubuntu: image: test/ubuntu command: sleep 99999 net: host
consul: image: test/ubuntu command: consul agent -join consul.aws.via-vox.net -data-dir /tmp -advertise 10.192.31.22 ports: - "8300:8300" - "8301:8301" - "8301:8301/udp" - "8302:8302" - "8302:8302/udp" - "8400:8400" - "8500:8500"
ubuntu: image: test/ubuntu command: sleep 99999 links: - consul
curl: (52) Empty reply from server
docker exec test_ubuntu_1 curl http://consul:8500
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to consul port 8500: Connection refused
conntrack -D -p udp ; docker-compose up
Seems you also need -bind 0.0.0.0 for the consul client
otherwise, it will bind to 127.0.0.1 if I recall correctly.
consul_1 | ==> WARNING: It is highly recommended to set GOMAXPROCS higher than 1consul_1 | ==> Starting Consul agent...consul_1 | ==> Starting Consul agent RPC...consul_1 | ==> Joining cluster...consul_1 | Join completed. Synced with 3 initial agentsconsul_1 | ==> Consul agent running!consul_1 | Node name: '6c684c6e26c4'consul_1 | Datacenter: 'dc1'consul_1 | Server: false (bootstrap: false)consul_1 | Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)consul_1 | Cluster Addr: 10.192.31.22 (LAN: 8301, WAN: 8302)consul_1 | Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: falseconsul_1 | Atlas: <disabled>
consul agent -join consul.aws.via-vox.net -data-dir /tmp -advertise 10.192.31.22 -bind 172.17.0.96
On Monday, 3 August 2015 18:12:02 UTC+1, Michael Fischer wrote:For now, as my application was not previously in Docker, it wasn't built to pick up everything from the environment. That can (probably should) be changed, although it's not always easy with legacy apps. At the very least, I could have a /start.sh that generates the necessary config file from the env vars.This is what we do, and I recommend it. You might also want to scrub sensitive environment variables in your start.sh script before exec'ing the application.Good to know that someone's using this method in practice. I'm just curious about the signalling though, does your application/container restart whenever one of the watched env keys gets changed in Consul?
Thanks, I've just tried that and still connection refused from host machine and other container.
consul agent -join $CONSUL_ADDRESS -data-dir /tmp -advertise $HOST_IP$ -client 0.0.0.0
"172.17.42.1:8500:8500"
That is a good question. Right now, we cannot use envconsul or consul-template to restart services automatically because they lack the ability to delay application reloads (beyond waiting for quiescence); synchronized reloads would cause a (temporary) outage that we cannot afford.I've filed enhancement issues against both to add a splay option to each:Until then, we have a few options:* In your service wrapper, catch SIGTERM/SIGINT and then reload the managed program after a random delay* Don't let consul-template run the program for you; run consul watch (or equivalent) out of band and send reload signals with it
envconsul -prefix test docker run -d my_container
envconsul -prefix test docker run my_container