Static IP for containers

How can i configure containers to have a static IP even after restart?

What is your use case that you need a static IP on the container?

If you really want to map an IP to a container, that is possible without managing the actual IP of the container.

  1. Add the IP as a secondary IP to the host
  2. start the container with ports published to that IP: docker run -p 1.2.3.4:443:443 -d mynginx

The normal docker networking stack is used. Your container’s published port listens on the secondary IP of 1.2.3.4. The actual container will get an auto-assigned IP address, but this is generally okay.

1 Like

But how can i connect to this IP (1.2.3.4 for example) from any place outside the docker host?

You would add 1.2.3.4 to the host as a secondary ip before you would do the docker run -p 1.2.3.4:443:443.