Docker, SkyDNS and SkyDock - fast and convenient

  • Tutorial
Not so long ago, I began to study what docker is , which has already managed to make a noise around the world. I will not go into the philosophical delights “why is it necessary?”, Or “fi, this is just another fashion trend!”, Or “who makes such a raw product?” I just want to give brief tips on how to quickly feel at home what docker is, using such benefits and amenities as SkyDock and SkyDNS .
This article is intended for people who have little time to read mountains in English (or do not know English), but there is little knowledge of what a console is and how to install docker yourself.
A brief summary of the article for the lazy
docker pull crosbymichael/skydns
docker pull crosbymichael/skydock
docker run -d -v /var/run/docker.sock:/docker.sock --name skydock crosbymichael/skydock -ttl 30 -environment dev -s /docker.sock -domain docker -name skydns
docker run -d -p --name skydns crosbymichael/skydns -nameserver -domain docker

The following is the configuration of the router or editing /usr/lib/systemd/system/docker.service, but for such details you still have to crawl under the habracat.

What are SkyDNS and SkyDock

SkyDNS allows you to raise your small DNS server. SkyDock , in turn, relying on data received from the bowels of the docker by communicating via a socket connection with the docker daemon, manages the zones in SkyDNS.
The SkyDNS + SkyDock bundle allows you not to worry about finding the IP addresses of containers running on your host. Actually it is service discovery.
Thus, you can run several containers with mongodb and practice collecting, say, a replica.
docker run -d --name repl1 mongo --smallfiles
docker run -d --name repl2 mongo --smallfiles
docker run -d --name repl3 mongo --smallfiles

We won’t go into the jungle of settings, but we’ll get some goodies from SkyDock:
- The ability to get the IP of a specific container by name
- The ability to get a list of IPs of all containers running on the basis of the mongo image, with the command dig
- The ability to get a list of IP addresses of all containers of this host teamdig dev.docker


It should take about 5 minutes for everything about everything (this, of course, depends on the speed of your connection to a great and powerful network).
Those who wish can watch a video where the author himself talks about SkyDock and launches this whole farm in real time

First you need to get the image of SkyDNS and SkyDock from the registry of images. The benefit of the image was prepared for us by a kind person named Michael Crosby (his github account , YouTube channel and, naturally, his docker registry hub ).
docker pull crosbymichael/skydns
docker pull crosbymichael/skydock

After a successful download, we need to execute the following commands:
docker run -d -p --name skydns crosbymichael/skydns -nameserver -domain docker

docker run -d -v /var/run/docker.sock:/docker.sock --name skydock crosbymichael/skydock -ttl 30 -environment dev -s /docker.sock -domain docker -name skydns

The first launches SkyDNS in a container named skydns and tells it in a human voice : “forward port 53 to port 53 of the host,” “use server if you don’t know the name that is being asked for from you” and “create a domain zone named docker. " Of course, the “docker” domain zone was chosen by me from the ceiling, here you can also indicate your domain “”.
The second command launches SkyDock, also in the container:
- name is given skydock;
- a socket is thrown inside the container /var/run/docker.sockto communicate with the docker daemon (depending on the system you are using, this parameter may need to be fixed);
- a 30 second TTL is set (as I understand it, this is the frequency of updating information in SkyDNS);
- the environment is given the name dev (the author plans to finish SkyDock for use on several hosts, so it will be possible to distinguish production from development);
- -ssimply indicates the path to the socket for communication;
- domain name docker;
- container name with SkyDNS - all of a sudden skydns!
Actually the installation is finished, SkyDNS and SkyDock are already working.

Network configuration

So, now we need to somehow convey for all comers the information that we now have our own, small, warm and tube (underline) DNS-service.
There are several options here.
In order for the containers to learn about each other while living on the same host, it is enough to specify the parameter in the command to start the docker daemon --dns. An example for the systemd unit is given in the spoiler below.
modified systemd-unit docker.service
$ cat /usr/lib/systemd/system/docker.service 
Description=Docker Application Container Engine
Documentation= docker.socket
ExecStart=/usr/bin/docker -d --bip= --dns= -H fd://

My situation is that at home there is a LAN with a small server, where the containers are spinning, and I work on a laptop. So you need to make sure that the laptop knows about the new dns server and uses it first.
To do this, I on the router:
- configured an additional routing rule that directs all traffic coming to it with destination addresses to my server;
- in the DHCP settings, the first to set the address is, and then the provider’s dns service.
And voila! Everything works at its best!

$ docker logs skydns 2>&1 | grep 'Received DNS' | awk -F\" '{print $2}' | sort | uniq

With this command you can see what domain names the devices from your LAN were interested in.
The abundance of advertising domains that interest mobile phones, for example ...

But what if you need to reboot?

To reboot the host, just do:
    docker stop skydock
    docker stop skydns

The actual reboot itself, and then:
    docker start skydns
    docker start skydock

On sim, I wish you a pleasant pastime with docker! :)

UPD. By the way, I will be very grateful if you leave your life hacks on using docker in the comments, or point to the names of all sorts of interesting pribluds for him. Well, or tell me what you yourself were interested in digging, maybe someone will also be interested?
UPD2. I enclose units for systemd for skydock and skydns.
Description=SkyDNS container
ExecStart=/usr/bin/docker start -a skydns
ExecStop=/usr/bin/docker stop -t 2 skydns

Description=SkyDock container
ExecStart=/usr/bin/docker start -a skydock
ExecStop=/usr/bin/docker stop -t 2 skydock

Also popular now: