Docker Community Forums

Share and learn in the Docker community.

Static IP on Docker containers


I am currently using Docker on my synology. After each reboot of my synology, my containers get a random IP in the pool.

I would like to be able to set the ips of my containers without having to create a new macvlan network.
The macvlan might cause me some communication problems between my containers.

Thanks in advance for your feedback.

Hi, I just tried to install docker on my synology, and it dosnt seem like it supports creating static ip for a network.

What you would do is creating a network manually, and then tell the container to use this network, using an ip you defined.

But this is possible if you ssh to the synology and use docker by cli.

Thank you for your reply.

The problem of using SSH is that my docker images are already in use with environment variables.

What is the solution ?

Do I have to make a docker composed of each docker with environment variables and then add the notion of static ip?


Not sure what you mean by “docker images are already in use with environment variables”.

Do I have to make a docker composed of each docker with environment variables and then add the notion of static ip?

Yes, then you add a static ip to that yml file

Running containers inside custom network provide you ability to sign containers with names, and use these names as DNS, avoiding IP utilization, like - docker network create mysupernetwork, docker run -d MyImageName (any other options) --name backend --network mysupernetwork and get access to it via http://backend from any other containers inside this network instead of or whatever.

If you really need to have a stable IP you have to run containers in the same order each time. For example it could be done with the docker-compose.yml where you will make a Chain for all containers using depends_on option.

This is litteraly an option provided by the compose file format:

It is possible to either assign fixed ipv4 and/or ipv6 ips for each network a conatiner is member of.

Though, if you depend on fix ip addresses, you high likely do something in way it is not supposed to be used. For container to container communication the prefered way is to use service discovery, which will allow to resolve the service names within a user defined network (like @pavelshalahai indicated). For outside to container communication you need to publish the container port and use the host ip or name and the host port of port mapping.

1 Like

Thanks, didn’t know about this feature/version.