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.
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.
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.
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! ')
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