📜 ⬆️ ⬇️

Docker, SkyDNS and SkyDock - quickly and conveniently

Not so long ago, I began to study what a docker is , which has already managed to make it all over the world. I will not go into the philosophical delights of "why is it necessary?", Or "fi, this is just another fashion trend!", Or "who produces such a raw product?". I just want to give brief advice on how quickly you can feel at home what a docker is, using benefits and amenities like SkyDock and SkyDNS .
This article is designed for people who have little time to read the article in English (or do not know English), but there is little knowledge of what a console is and how to install the 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 172.17.42.1:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -domain docker 

This is followed by setting up the router or editing /usr/lib/systemd/system/docker.service , but such details will still have to get under the habrak.


What is SkyDNS and SkyDock


SkyDNS allows you to raise your small DNS server. SkyDock , in turn, relying on data obtained from the depths of the docker by communicating via a socket connection with the docker daemon, controls the zones in SkyDNS.
A bunch of SkyDNS + SkyDock allows you not to suffer from the search for IP-addresses of containers running on your host. In fact, this is service discovery.
This way you can run multiple 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 will not go into the wilds of setting the monga, but what are the buns from SkyDock we get:
- The ability to get the IP of a specific container named repl2.mongo.dev.docker
- Ability to get a list of IP of all containers running on the basis of the mongo image, with the dig mongo.dev.docker
- Ability to get a list of IP-addresses of all containers of this host with the dig dev.docker

Installation


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


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

After a successful download, we need to run the following commands:
 docker run -d -p 172.17.42.1:53:53/udp --name skydns crosbymichael/skydns -nameserver 8.8.8.8:53 -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 one launches SkyDNS in a container named skydns and tells it with a human voice : “forward port 53 to port 53 of host 172.17.42.1”, “use server 8.8.8.8 if you don't know the name you are asked to do” and “create a domain zone named docker. " Of course, the docker domain zone was chosen by me from the ceiling; here you can also specify your example.com domain.
The second team launches SkyDock, also in a container:
- the name is given skydock ;
- a socket /var/run/docker.sock into the container to communicate with the docker daemon (depending on the system you are using, you may need to correct this parameter);
- a 30 second TTL is set (as far as I understand, 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, thus it will be possible to distinguish production from development);
- -s simply indicates the path to the socket for communication;
- docker domain name;
- container name with SkyDNS - suddenly skydns !
The installation itself is complete, SkyDNS and SkyDock are already working.

Network configuration


So, now we need to somehow convey to everyone who wants information that we now have our own, small, warm and lamp (please underline) DNS service.
There are several options here.
In order for the containers to find out about each other while living on the same host, it suffices to specify the --dns parameter in the command for starting the docker --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 [Unit] Description=Docker Application Container Engine Documentation=http://docs.docker.com After=network.target docker.socket Requires=docker.socket [Service] ExecStart=/usr/bin/docker -d --bip=172.17.42.1/16 --dns=172.17.42.1 -H fd:// LimitNOFILE=1048576 LimitNPROC=1048576 [Install] WantedBy=multi-user.target 


In my case, the situation is such that at home there is a lokalka with a small server where the containers spin, 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.
For this, I'm on the router:
- set up an additional routing rule that sends all traffic coming to it with destination addresses 172.0.0.0/8 to my server;
- in the DHCP settings, the first to set the address is 172.17.42.1, and then the provider’s dns-service.
And voila! Everything works at its best!
')
bun
 $ docker logs skydns 2>&1 | grep 'Received DNS' | awk -F\" '{print $2}' | sort | uniq 

With the help of this command, you can see what domain names the devices from your local network are interested in.
Immediately struck by the abundance of advertising domains that are interested in mobile phones, for example ...

And what if you need to reboot?


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

Actually reboot itself, and then:
  docker start skydns docker start skydock 

Beauty!
On this I wish you a pleasant stay with docker! :)

UPD. By the way, I will be very grateful if you leave your comments on how docker uses in your comments, or point to the names of all sorts of different interesting things for him. Well, or tell me what you yourself was interesting to pick, maybe someone will also be interested?
UPD2. I attach units for systemd for skydock and skydns.
skydns.service
 [Unit] Description=SkyDNS container Requires=docker.service [Service] Restart=always ExecStart=/usr/bin/docker start -a skydns ExecStop=/usr/bin/docker stop -t 2 skydns [Install] WantedBy=multi-user.target 


skydock.service
 [Unit] Description=SkyDock container After=docker.service Requires=skydns.service [Service] Restart=always ExecStart=/usr/bin/docker start -a skydock ExecStop=/usr/bin/docker stop -t 2 skydock [Install] WantedBy=multi-user.target 

Source: https://habr.com/ru/post/246933/


All Articles