Ajeet Raina Docker Captain, ARM Innovator & Docker Bangalore Community Leader.

Demonstrating Docker 1.12 Service Discovery with Docker Compose

1 min read

CofvQBxUAAE1UpT

Docker 1.12 is GA now. Thanks to Docker Inc. core Team and community support for releasing it on time as promised during DockerCon 2016.In my earlier post, I briefed around Service Discovery concept and how does it work in terms of  Swarm Mode. As we are well aware, Swarm Mode is an optional mode which can be ON and OFF based on your choice and requirement. Under this blog post, I am going to demonstrate service discovery while playing around with docker-compose.

Compose

I have a Ubuntu 16.04 machine upgraded with Docker 1.12 GA version. I have docker-compose 1.8.0 running on the same machine. To demonstrate how one service discover others through hostname, I am going to build a very simple Nginx application and a proxy which redirects to the default Nginx web application through the following structure:

Docker_11

The collabapp contains a very simple Dockerfile which pulls nginx running alpine image from Dockerhub.

Docker_12

 

The collabproxy contains Dockerfile to use the same nginx image with the customized proxy.conf. All it does is whenever there is any request coming to port: 80 will be redirected to http://collabapp which is nothing but a container running web application.

Docker_13

A quick look at docker-compose.yml file:

Docker_19

One thing which you would notice here is that we are NOT providing any “link:” parameter for linking both the services. Docker 1.12 handles this service name aspect internally through the in-built service discovery concept.

Let’s build up the containers using docker-compose as shown below:

Docker_14

Let’s bring up both the containers:

Docker_15

There are two services running – test_collabapp_1 and test_collabproxy_1. You can view the services running in a single shot as shown:

Docker_16

Let’s try to reach out to collabapp from within collabproxy using hostname and see if internal DNS resolves that or not.

Docker_16

As shown above, we are able to ping web application from proxy container using hostname.

To see how does it resolve that hostname, let us look up few interesting files inside the container:

Docker_17

Also, the mount command too shows how the /etc/resolv.conf, /etc/hostname and related files are created for service discovery to be enabled.

Docker_18

The 127.0.0.11 is an embedded DNS server which enables the service discovery functionality.The embedded DNS server is really a light weight server only interested in responding to container name/alias queries and for everything else it just acts as the proxy to any other DNS server.There is a socket created in the container namespace and which listens on it in the daemon itself and respond queries using that. The socket acts as the demux identifier to identify the network in case of unqualified name queries.

Let’s look at an interesting aspect of Service Discovery while we scale the service to run multiple containers across the same machine.

Docker_20

Now, the docker-compose ps shows scaled value of 5.

Docker_21

If you enter into collabproxy container and try to check the nslookup output:

Docker_23

Wow ! The command returned five different IP addresses from in-built DNS and all it does is round-robin DNS to load-balance across those 5 different containers.

 

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Docker Captain, ARM Innovator & Docker Bangalore Community Leader.

31 Replies to “Demonstrating Docker 1.12 Service Discovery with Docker Compose”

  1. the dns picks up the upscaled containers in it’s response. But the nginx collabproxy resolves the host in the proxy_pass instruction only on startup, so it does not benefit from that.

  2. @Peter
    You are right, as a workaround I scaled collabproxy=0 and again collabproxy=1 to get it load balancing with the additional collabapp instances

  3. Thanks , I have recently been searching for info approximately this topic for ages and yours is the greatest I’ve found out till now. However, what in regards to the bottom line? Are you sure concerning the source?

  4. Hello there, just became alert to your blog through Google, and found that it is really informative. I am gonna watch out for brussels. I’ll appreciate if you continue this in future. A lot of people will be benefited from your writing. Cheers!

  5. Howdy just wanted to give you a quick heads up and let you know a few of the images aren’t loading correctly. I’m not sure why but I think its a linking issue. I’ve tried it in two different web browsers and both show the same results.

  6. Hmm it looks like your blog ate my first comment (it was extremely long) so I guess I’ll just sum it up what I submitted and say, I’m thoroughly enjoying your blog. I as well am an aspiring blog writer but I’m still new to the whole thing. Do you have any suggestions for newbie blog writers? I’d certainly appreciate it.

  7. I am now not sure where you’re getting your info, however great topic. I must spend a while learning much more or working out more. Thank you for fantastic info I was in search of this info for my mission.

  8. Thank you for your own labor on this web page. Betty loves getting into internet research and it is easy to see why. A lot of people notice all of the powerful manner you give vital information via the blog and increase response from others on this topic so our own daughter is now learning a lot of things. Take pleasure in the remaining portion of the new year. You are doing a really great job.

  9. Very good blog! Do you have any hints for aspiring writers? I’m hoping to start my own site soon but I’m a little lost on everything. Would you recommend starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m totally confused .. Any suggestions? Appreciate it!

  10. I’d have to examine with you here. Which is not one thing I usually do! I take pleasure in reading a post that may make folks think. Additionally, thanks for permitting me to comment!

  11. There are some interesting points in time in this article but I don’t know if I see all of them middle to heart. There’s some validity however I’ll take hold opinion until I look into it further. Good article , thanks and we want extra! Added to FeedBurner as effectively

  12. Hi , I do believe this is an excellent blog. I stumbled upon it on Yahoo , i will come back once again. Money and freedom is the best way to change, may you be rich and help other people.

  13. Thank you for the good writeup. It in fact was a amusement account it. Look advanced to more added agreeable from you! By the way, how can we communicate?

  14. I like what you guys are up too. Such smart work and reporting! Keep up the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my web site 🙂

  15. I was just seeking this info for some time. After six hours of continuous Googleing, at last I got it in your site. I wonder what is the lack of Google strategy that do not rank this kind of informative websites in top of the list. Generally the top sites are full of garbage.

  16. Youre so cool! I dont suppose Ive learn anything like this before. So good to find somebody with some original thoughts on this subject. realy thank you for beginning this up. this web site is one thing that’s needed on the web, someone with slightly originality. helpful job for bringing one thing new to the internet!

Leave a Reply

Your email address will not be published.