I am trying to run a number of containers (custom image) equal to the number provided at the command line when running the script. I suppose I could use swarm
too but figured this would work too and might be a better user experience if I distributed it (I don't know).
The script I have so far:
#!/bin/bash
docker build ./client -t python-mqtt-client
while getopts ":n:i:f:" opt; do
case ${opt} in
n ) number=$OPTARG
;;
i ) interval=$OPTARG
;;
f ) format=$OPTARG
;;
esac
done
echo ${number}
echo ${interval}
for i in {1..${number}}
do
docker run -d --network mqtt-demo_default --name py-mqtt-client${i} python-mqtt-client /mqtt_client.py --interval ${interval} --format ${format}
done
It only seems to spin up one container each time I run it even when I run it with n
> 1...like script.sh -n 5 -i 1 -f json
For reference, here's the Dockerfile that creates this image:
# syntax=docker/dockerfile:1
FROM python:3.8-slim-buster
ADD requirements.txt /
ADD mqtt_client.py /
RUN pip3 install -r requirements.txt
CMD ["/mqtt_client.py"]
ENTRYPOINT ["/usr/local/bin/python3"]