I am using docker-compose healthcheck to test network connectivity between two network segments. I have iperf running in server mode within containers on one host and iperf in client mode within containers on a different host. Here is sample docker-compose healthcheck configuration on the client side:
Each client container starts and connects to a different iperf server port (i.e. 5200-5209). This is easy enough if I create each container as a separate service within my compose file and hard code the port, however, that isn’t very scalable. I’d like to be able to pass healthcheck something like:
and have docker-compose iterate through the port numbers exactly like it does if I specify a port range using the “ports” configuration option when using --scale in my “up” command. Is there an iterator variable available in docker compose I can use for this purpose?
Thank you,
Chris
The ports command you reference will configure port mapping for the container … I don’t need the container ports mapped (external->internal) … just a way to change the port number in my test command as --scale iterates through starting containers. My client containers come up with their own ips, so don’t need to map ports.
I use port mapping on the server side, exactly as you mention.
The reference to the docker compose file does not include any reference to such a thing.
Though, Swarm services are able to use template placeholder in some of the configuration elements to individualize each replica.
You might assign {{.Task.Slot}} to an env and use it in your entrypoint script to add the task slot on top of your base port.