• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

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