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 -d mynginx

The normal docker networking stack is used. Your container’s published port listens on the secondary IP of 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 ( for example) from any place outside the docker host?

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