Multiple static IPs for Docker containers

后端 未结 2 421
花落未央
花落未央 2021-02-06 02:44

I have a Docker host that should allow each container to have multiple static IP addresses. The application inside the container should then be able to choose from which address

相关标签:
2条回答
  • 2021-02-06 03:05

    Every docker container has a single IP only. We can set custom IP also, by making a bridge network as,

    docker network create net1 --driver=bridge --subnet="192.168.0.1/27"

    If you don't mention the driver then by default it is bridge network.

    So here using --subnet, you can give a custom IP address to the network and using that network, you can also give custom IP addresses to the containers which are inside that network.

    Then run a container as,

    docker run -it --network=net1 --ip="192.168.0.3" --name=MyContainer image_name

    Now, in this way you can make 32-27=5 i.e., (2^5)-2 docker containers.

    0 讨论(0)
  • 2021-02-06 03:20

    I think you can do it by customizing docker0 bridge, or even create your own network bridge

    0 讨论(0)
提交回复
热议问题