Docker Community Forums

Share and learn in the Docker community.

Static IP for containers


(Maitarek) #1

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


(Jeff Anderson) #2

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.


(Maitarek) #3

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


(Jeff Anderson) #4

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.