Skip to content

Demonstrating Docker 1.12 Service Discovery with Docker Compose

Last updated on 13th December 2017

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.

 

0
Published inDockerDocker Compose

64 Comments

  1. You actually make it appear really easy together with your presentation however I to find this topic to be actually something that I think I’d never understand. It seems too complex and extremely vast for me. I am having a look ahead to your subsequent post, I’ll try to get the grasp of it!

  2. My coder is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the costs. But he’s tryiong none the less. I’ve been using WordPress on a variety of websites for about a year and am concerned about switching to another platform. I have heard good things about blogengine.net. Is there a way I can import all my wordpress content into it? Any help would be really appreciated!

  3. It¦s in reality a great and useful piece of info. I¦m happy that you just shared this useful information with us. Please keep us informed like this. Thank you for sharing.

  4. Wow! This blog looks just like my old one! It’s on a completely different subject but it has pretty much the same page layout and design. Excellent choice of colors!

  5. Hi there! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains. If you know of any please share. Appreciate it!

  6. We absolutely love your blog and find most of your post’s to be precisely what I’m looking for. Does one offer guest writers to write content for you? I wouldn’t mind writing a post or elaborating on many of the subjects you write with regards to here. Again, awesome web site!

  7. I just could not depart your website before suggesting that I actually enjoyed the standard information a person provide for your visitors? Is going to be back often to check up on new posts

  8. Great wordpress blog here.. It’s hard to find quality writing like yours these days. I really appreciate people like you! take care

  9. I see something truly special in this internet site.

  10. Appreciate it for helping out, superb information. “Courage comes and goes. Hold on for the next supply.” by Vicki Baum.

  11. I dugg some of you post as I thought they were extremely helpful extremely helpful

  12. What’s Happening i am new to this, I stumbled upon this I’ve found It positively helpful and it has helped me out loads. I hope to contribute & aid other users like its aided me. Good job.

  13. After study a few of the blog posts on your website now, and I truly like your way of blogging. I bookmarked it to my bookmark website list and will be checking back soon. Pls check out my web site as well and let me know what you think.

  14. I was looking at some of your blog posts on this internet site and I believe this site is real informative ! Keep putting up.

  15. I’ve been exploring for a little for any high quality articles or weblog posts on this sort of space . Exploring in Yahoo I ultimately stumbled upon this web site. Reading this info So i am glad to convey that I’ve an incredibly good uncanny feeling I discovered just what I needed. I most indisputably will make certain to do not fail to remember this website and give it a glance on a continuing basis.

  16. Valuable info. Lucky me I found your site by accident, and I am shocked why this accident didn’t happened earlier! I bookmarked it.

  17. Really wonderful info can be found on web blog. “You don’t get harmony when everybody sings the same note.” by Doug Floyd.

  18. Great line up. We will be linking to this great article on our site. Keep up the good writing.

  19. I wanted to write down a simple remark to appreciate you for these awesome information you are showing on this site. My time consuming internet investigation has at the end been recognized with reputable concept to exchange with my great friends. I would admit that we site visitors are very fortunate to exist in a superb network with so many lovely people with beneficial strategies. I feel very happy to have come across the website and look forward to some more brilliant times reading here. Thanks once more for all the details.

  20. I enjoy studying and I conceive this website got some really useful stuff on it! .

  21. Pretty component of content. I just stumbled upon your web site and in accession capital to claim that I get actually loved account your blog posts. Any way I will be subscribing in your feeds and even I fulfillment you access constantly quickly.

  22. What i do not realize is if truth be told how you are not really a lot more smartly-liked than you may be now. You’re so intelligent. You understand thus significantly relating to this subject, produced me personally consider it from a lot of numerous angles. Its like women and men don’t seem to be involved until it is one thing to accomplish with Lady gaga! Your individual stuffs excellent. At all times maintain it up!

  23. It?¦s actually a nice and helpful piece of information. I?¦m glad that you simply shared this helpful information with us. Please keep us informed like this. Thanks for sharing.

  24. I like what you guys are up also. Such intelligent work and reporting! Carry on the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my site 🙂

  25. That is very interesting, You’re an excessively skilled blogger. I’ve joined your feed and look forward to searching for more of your magnificent post. Additionally, I’ve shared your site in my social networks!

  26. I actually wanted to construct a simple message to say thanks to you for those great tips you are giving at this website. My particularly long internet look up has finally been honored with high-quality information to write about with my contacts. I ‘d tell you that many of us website visitors are rather blessed to live in a remarkable website with many awesome people with very beneficial pointers. I feel somewhat grateful to have seen your site and look forward to tons of more enjoyable moments reading here. Thank you once more for all the details.

  27. It’s really a nice and helpful piece of info. I am glad that you shared this helpful information with us. Please keep us informed like this. Thanks for sharing.

  28. The crux of your writing whilst sounding reasonable in the beginning, did not really work properly with me after some time. Someplace throughout the paragraphs you actually were able to make me a believer unfortunately only for a while. I still have a problem with your jumps in assumptions and you might do well to help fill in all those breaks. When you actually can accomplish that, I would surely end up being amazed.

  29. Hi just wanted to give you a quick heads up and let you know a few of the images aren’t loading properly. 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.

  30. My husband and i got quite more than happy when Edward managed to do his investigation using the ideas he received from your web page. It is now and again perplexing just to happen to be releasing tips which people today might have been making money from. Therefore we acknowledge we have the writer to be grateful to because of that. The most important illustrations you’ve made, the simple blog menu, the friendships you will give support to promote – it is all extraordinary, and it is assisting our son in addition to our family understand the topic is exciting, which is certainly especially important. Thank you for the whole thing!

  31. I like what you guys are up too. Such intelligent work and reporting! Carry on the excellent works guys I have incorporated you guys to my blogroll. I think it’ll improve the value of my website 🙂

  32. Currently it looks like Drupal is the top blogging platform out there right now. (from what I’ve read) Is that what you are using on your blog?

  33. Hello. impressive job. I did not anticipate this. This is a impressive story. Thanks!

  34. I’m so happy to read this. This is the kind of manual that needs to be given and not the accidental misinformation that’s at the other blogs. Appreciate your sharing this best doc.

  35. Glad to be one of the visitors on this awe inspiring website : D.

  36. I discovered your blog site on google and check a few of your early posts. Continue to keep up the very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking forward to reading more from you later on!…

  37. What i don’t realize is if truth be told how you’re not actually much more well-favored than you might be now. You’re so intelligent. You understand thus significantly in terms of this topic, made me in my view consider it from so many various angles. Its like women and men are not fascinated except it’s something to accomplish with Girl gaga! Your individual stuffs excellent. At all times deal with it up!

  38. Hello, Neat post. There’s a problem along with your web site in web explorer, may check this?K IE nonetheless is the market chief and a large part of other folks will leave out your magnificent writing because of this problem.

  39. I am extremely impressed together with your writing abilities and also with the format on your blog. Is that this a paid subject or did you customize it yourself? Anyway keep up the nice quality writing, it’s uncommon to peer a nice weblog like this one nowadays..

  40. You completed several good points there. I did a search on the topic and found nearly all persons will have the same opinion with your blog.

  41. I regard something genuinely interesting about your blog so I saved to favorites.

  42. I was very happy to seek out this web-site.I wished to thanks on your time for this glorious read!! I positively having fun with each little little bit of it and I have you bookmarked to check out new stuff you blog post.

  43. Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something. I think that you could do with some pics to drive the message home a bit, but other than that, this is magnificent blog. A great read. I will certainly be back.

  44. I’m really inspired together with your writing abilities and also with the layout for your blog. Is that this a paid topic or did you modify it yourself? Either way stay up the excellent quality writing, it?s rare to look a nice blog like this one these days..

  45. I am no longer certain the place you are getting your information, however good topic. I needs to spend a while finding out much more or working out more. Thank you for wonderful info I used to be searching for this information for my mission.

  46. Some really nice and utilitarian information on this internet site, likewise I conceive the style and design holds excellent features.

  47. Howdy, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam comments? If so how do you stop it, any plugin or anything you can suggest? I get so much lately it’s driving me insane so any support is very much appreciated.

  48. My wife and i ended up being so thankful John managed to deal with his research using the ideas he made from your web site. It is now and again perplexing just to find yourself giving away tactics which often some others might have been selling. We figure out we’ve got the website owner to give thanks to because of that. Most of the explanations you’ve made, the straightforward blog navigation, the relationships you will assist to engender – it is mostly exceptional, and it is helping our son in addition to the family imagine that the issue is cool, and that’s pretty essential. Thanks for the whole lot!

  49. Howdy! I just want to give a huge thumbs up for the nice data you may have right here on this post. I shall be coming back to your blog for extra soon.

  50. I do accept as true with all the ideas you’ve offered on your post. They are very convincing and will definitely work. Still, the posts are very quick for novices. May just you please lengthen them a little from next time? Thanks for the post.

  51. My brother suggested I might like this website. He was entirely right. This post actually made my day. You can not imagine just how much time I had spent for this information! Thanks!

  52. There is visibly a lot to identify about this. I believe you made certain nice points in features also.

  53. We are a group of volunteers and opening a new scheme in our community. Your site provided us with valuable info to work on. You’ve done an impressive job and our whole community will be grateful to you.

  54. I discovered your blog website on google and examine a number of of your early posts. Proceed to maintain up the excellent operate. I simply further up your RSS feed to my MSN News Reader. Searching for ahead to studying extra from you afterward!…

Leave a Reply to Anonymous Cancel reply

Your email address will not be published.