how could i get nodes ip and container ip (running on manager(s) and workers(s) node(s) ) from a created service? I'd like to inspect this for studying round robin load balancing of docker swarm engine and develop a new load balancing.
You can easily get the IP address of any container if you have the name or ID of the container. You can get the container names using the "Docker ps -a" command. This will list all the existing containers.
for getting the node IP address, the value is in different places depending on if the node is a worker or a manager. docker node inspect node1 --pretty ID: 0lkd116rve1rwbvfuonrfzdko Hostname: node1 Joined at: 2022-09-18 16:16:28.6670527 +0000 utc Status: State: Ready Availability: Active Address: 192.168.
IPVS keeps track of all the IP addresses participating in that service, selects one of them, and routes the request to it, over the ingress network. The ingress network is created automatically when you initialize or join a swarm.
By default, the container is assigned an IP address for every Docker network it connects to. The IP address is assigned from the pool assigned to the network, so the Docker daemon effectively acts as a DHCP server for each container. Each network also has a default subnet mask and gateway.
To get the node IP address you can use below command:
docker node inspect self --format '{{ .Status.Addr }}'
To get the service IP address, Just add service-id in the end, like:
docker node inspect self --format '{{ .Status.Addr }}' service-id
To get the container IP address, use:
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container-id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With