A
A
Andrey2018-08-14 18:21:13
Domain Name System
Andrey, 2018-08-14 18:21:13

How to configure DNS names for Docker containers?

I'm just getting started with docker. Now I “stopped” at the “stage” between docker-compose and kuberneters. I understand how to deploy an environment for a project, how to set up docker-compose.yml, but there is a practical problem.
At work (web developer) you need to run several “projects” (for example, front and back) and each time it’s not very easy to go to IP.
Now the working machine that is planned to be “transferred” to docker is configured as follows: Apache is installed on it, with all the bindings (mysql, php, phpmyadmin), there is a dns server (dnsmasq) and it redirects all requests with the .dev domain to the local machine , and Apache, when receiving a request, takes a 2nd level domain (for example, it will take test from test.dev) and works with a folder that is named after this domain. Those. everything is configured so that when you create a folder in the working directory, you can immediately access it by going to http://folder-name.dev.
And actually the question is how to configure dnsmasq and docker so that the docker understands which container to redirect the request to? Those. so that when accessing test.devThe dns server sent a request to docker, and the domain-based docker (test) understood what needed to be sent to the container in the project.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2018-08-15
@andreybold

Consul.
running containers are registered in the Consul server, the consul itself can, among other things, also have a DNS service. That is, each running container will automatically be registered in DNS and can be accessed by the given name. And the consul can also change the configuration of the web server, which stands in front and add delete virtual hosts or locations there, as you set it up yourself. But! You need to sit down and figure out exactly how it works.
Here is a good article on Habré, and its second part is directly on your question.

S
Sanes, 2018-08-14
@Sanes

Isn't it easier to put Nginx at the entrance?

O
OnYourLips, 2018-08-14
@OnYourLips

You need an entry point.
The easiest option for docker is nginx with configured proxy pass to container ports.
In the case of kubernetes, you will also need ingress.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question