• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion
  • Inviting everyone to the UX test of a new security feature in the WP Toolkit
    For WordPress site owners, threats posed by hackers are ever-present. Because of this, we are developing a new security feature for the WP Toolkit. If the topic of WordPress website security is relevant to you, we would be grateful if you could share your experience and help us test the usability of this feature. We invite you to join us for a 1-hour online session via Google Meet. Select a convenient meeting time with our friendly UX staff here.

Question Docker bind dedicated IP addresses to containers

kwendel

New Pleskian
Hi there!
I am running Plesk on a Ubuntu Server with multiple external IP addresses and want to bind an unused, dedicated ip address to a docker container.

So for example:
  • Main IP (shared) is 123.123.123.100
  • Docker Container 1 should be binded to 123.123.123.101 exclusively
  • Docker Container 2 should be binded to 123.123.123.102 exclusively
So i can use the same internal/external port for conainters.

And the setting sould be permanent, so that i can restart the containers over the Plesk Panel without loosing these bindings :)

I looked through the internet and forums but only could find a "docker run" command that binds to a specific ip address.
but this will not work if i am restarting the container over the docker menu in plesk panel.

Thanks for any help!
 
Hi,

I have the same question but only found this old post without any answer. Is it possible to route IPs to running docker containers?

Thanks!
Bruno
 
This depends how your container is connected to the network (which driver is used).

Basically if your container connects to user defined networks and has an IPAMConfig key you can set a static IP here, for example:

docker inspect <container>

JSON:
"NetworkSettings": {
        "Bridge": "",
        "EndpointID": "",
        "Gateway": "",
        "GlobalIPv6Address": "",
        "GlobalIPv6PrefixLen": 0,
        "HairpinMode": false,
        "IPAddress": "",
        "IPPrefixLen": 0,
        "IPv6Gateway": "",
        "LinkLocalIPv6Address": "",
        "LinkLocalIPv6PrefixLen": 0,
        "MacAddress": "",
        "Networks": {
            "local": {
                "Aliases": [
                    "cc50756b4286"
                ],
                "DriverOpts": null,
                "EndpointID": "9a7b5c63d05...",
                "Gateway": "172.21.0.1",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "IPAMConfig": {
                    "IPv4Address": "172.21.0.3"
                },
                "IPAddress": "172.21.0.3",
                "IPPrefixLen": 16,
                "IPv6Gateway": "",
                "Links": null,
                "MacAddress": "02:42:ac:15:00:03",
                "NetworkID": "11d4d75df6ef39..."
            }
        },
        "SandboxID": "46fee1097b31...",
        "SecondaryIPAddresses": null,
        "SecondaryIPv6Addresses": null
    },

If IPAMConfig ist not set, the default Network.IPAddress-key seems to work only for the standard bridge network but not for user created networks (but it may depend on the system):

JSON:
        "Networks": {
            "bridge": {
                "Aliases": null,
                "DriverOpts": null,
                "EndpointID": "1e7b279500....",
                "Gateway": "172.17.0.1",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "IPAMConfig": null,
                "IPAddress": "172.17.0.3",
                "IPPrefixLen": 16,
                "IPv6Gateway": "",
                "Links": null,
                "MacAddress": "02:42:ac:11:00:03",
                "NetworkID": "3a1822b3069...."
            }
        },

AFAIK docker still lacks an update command for that so you need to edit the configuration file (usually in):
/var/lib/docker/<container id>/config.v2.json

If you don't know how to set up your configuration properly just run a new container with the --ip argument set and inspect the configuration that was created.
 
Back
Top