jwilder / docker-discover Goto Github PK
View Code? Open in Web Editor NEWService discovery for docker container
License: MIT License
Service discovery for docker container
License: MIT License
docker run -d --net host --name docker-discover -e ETCD_HOST=192.168.56.102:4001 -p 1936:1936 -t jwilder/docker-discover
docker logs docker-discover
Error: 'Key not found : /backends'
Error: 'Key not found : /backends'
Error: 'Key not found : /backends'
Error: 'Key not found : /backends'
service on 1936 is unreacheable. Also whoami servers is unreacheable.
If I try to connect directly to a single whoami serv it works fine.
The python script should handle its child processes (reload-haproxy.sh) properly to avoid zombies.
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
works for me.
First of all, these set of scripts, and your blog post, are awesome. I've got everything running as described and it's great. I did run into issues however when using this with private registries.
I'm about 100% sure it has to do with the section of code that looks for 2 / marks to verify if it's a valid registry. With a private registry there will also be a full url. For example:
my.private-registry.com/my/image
Hi,
Thanks for this great job!
I am trying the demo 'whoami', and haproxy works fine. I was able to see backend container id.
But when I deployed my own services on one backend server x.x.x.2
2600516615c7
from Image service1
exposed port 0.0.0.0:8080->5001/tcp
a6fc817cbca3
from Image service2
exposed port 0.0.0.0:443->5000/tcp
814d49616255
from Image service1
exposed port 0.0.0.0:8080->5001/tcp
31eb936f2e59
from Image service1
exposed port 0.0.0.0:8080->5001/tcp
docker-discover is deployed on server x.x.x.1
But when call service1 api from address x.x.x.1:8080, I got
connect to x.x.x.1 port 8080: Connection refused
I curl etcd for key 'backends/service1', it showed me 3 sub nodes 'backends/service1/2600516615c7',
'backends/service2/814d49616255', 'backends/service1/port'
And for haproxy config, I see
listen service1
bind *:5001
server 814d49616255 x.x.x.2:8080 check inter 2s rise 3 fall 2
server 2600516615c7 x.x.x.3:8080 check inter 2s rise 3 fall 2
Hello,
First, thanks for all your projects around docker - they are great help.
One issue that I've been noticing is that when I have more than one container of the same service, the haproxy config would start reloading every 10-15 seconds even tho there were no change.
The issue is that etcd doesn't send back the nodes in the same order every time, and docker-discover would detect a change even tho it was just the same nodes, not in the same order.
A way to avoid this would be to have get_services() sort its results so that no change would be detected when nodes are swapped in the etcd response
I wrote a workaround, but I'm no python expert and it's too dirty to put in a pull request, but here it is anyway:
if name == "main":
current_services = {}
while True:
changed = False
try:
services = get_services()
if not services or services == current_services:
time.sleep(POLL_TIMEOUT)
continue
else:
numberServices = len(services.items())
current_numberServices = len(current_services.items())
# print "numberServices = " + str(numberServices)
# print "current_numberServices = " + str(current_numberServices)
if numberServices == current_numberServices:
# "No new services... lets check them"
for i in range(numberServices):
if services.items()[i][0] == current_services.items()[i][0]:
# "Same services... Same values?"
regex = re.compile('[0-9]+.[0-9]+.[0-9]+.[0-9]+\:[0-9]+')
ipServices = sorted(re.findall(regex, str(services.items()[i])))
current_ipServices = sorted(re.findall(regex, str(current_services.items()[i])))
if ipServices == current_ipServices:
else:
changed = True
break;
else:
changed = True
break;
if changed == True:
print "config changed. reload haproxy"
generate_config(services)
ret = call(["./reload-haproxy.sh"])
if ret != 0:
print "reloading haproxy returned: ", ret
time.sleep(POLL_TIMEOUT)
continue
current_services = services
except Exception, e:
print "Error:", e
time.sleep(POLL_TIMEOUT)
I'm sure all of this could be done with a one liner sorting in get_services tho
Regards,
Exposing ports using -p option is not valid when using the host network stack. When attaching to the host network stack, it's meaningless to ask docker to bind a container port on a host port. The haxproy stats interface is thus not exposed by default
I started a fork for my own personal cloud of servers, but am worried that there isn't a license. Would it be reasonable to request that a license be added so that people whom may be unsure can use this as well?
Thanks! This is a neat project :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.