I am trying to set a static IP address inside a docker container (using a CentOS image with systemctl enabled).
The reason for this is, that I want to run a service inside a container which requires ssh and checks if a NIC with the IP it should listen on is available. The service communicates with other services in the same network so the IP needs to be accessible from outside the container as well.
It potentially could work with --net=host, but I could never figure how I would bind a range of ports to the container with that option. Using -p 10.2.0.253:22:22 does not work. When using e.g. SSH from any physical node on that network, I always end up on the docker host instead inside the container.
- The network is 10.2.0.0/24.
- The docker host has the IP 10.2.0.100
- Container should listen to all ports on 10.2.0.253 and most important, there must be an interface within the container with that IP
- The container should be reachable from any physical node or container on the 10.2.0.0/24 network
Is there any way make this work?