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:
healthcheck: test: iperf3 -V --logfile iperf3_client_log -c 172.29.128.8 -p 5200 interval: 60s timeout: 40s start_period: 5s retries: 1
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:
iterator: 5200-5209 test: iperf3 -V --logfile iperf3_client_log -c 172.29.128.8 -p $iterator
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?