A
A
Alexander2015-06-05 18:49:52
linux
Alexander, 2015-06-05 18:49:52

How to make static ip for docker container?

Discovered Docker. Within the same machine, I want to raise two Docker containers (in one apache + php in another mysql), which should interact with each other via tcp (in the future it is planned to spread to different servers)
The question is: what to do when the Docker container changes his ip address?
That is, the first container will not be able to connect to the second if it is restarted.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nazar Mokrinsky, 2015-06-05
@nazarpc

You need to link one container to another, then inside the other it will be possible to access not by IP, but by name. And to formalize this case, you can use Docker compose - this way you define a set of containers that together provide a ready-made service.
Example: https://github.com/nazar-pc/docker-webserver#how-to-use
There, in separate containers PHP-FPM, Nginx, MariaDB, SSH, everything links to each other, everything is optional, everything can be updated by separately.
Also, official images, the same mysql are made in a similar way - link it where you need it, in that container you already connect by the name mysql, regardless of its IP.
For example, you can take the official PHP image (which is already bundled with Apache2) and the official MySQL image, customize if necessary (you can use it as a basis for your image) and everything will work.

A
Alexander, 2015-06-05
@savio

if I understand the situation correctly, then the interaction of two or more containers within the same server through linking, if the containers are on different servers, then through tcp.
And yet, is issuing the same IP 172.17.0.6 (and not 172.17.0.2 and so on ...) really such a difficult task in Docker?

S
Sergey Fadeev, 2015-06-15
@fadeev2010

As one of the options, you can use SkyDock + SkyDNS , and access containers by dns name, when you enable / add a new container, a record about it will be dynamically added.
And thus you do not need to know the IP address of the container.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question