We have a docker-compose.yml file to bring up a db2 and a number of other components of our testing framework. Once we bring up the db2 we have to attach to that container and run a set of shell scripts on it to create schema definitions, etc.
Trouble is that docker-compose gives dynamic names to the containers - and they change everytime we start them with 'run'. How do I find the exact name of the db2 container that's running this time?!
Here is an excerpt from our docker-compose.yml:
db2:
container_name: "bluecost-db2"
image: store/ibmcorp/db2_developer_c:11.1.3.3-x86_64
command: /bin/bash -c "groupadd bluecost -g 1006;adduser bluecost -u $$(id -u) -g $$(echo $$(id)| grep -oPm1 'gid=\K\w+')&& echo \"bluecost:bluecost\" | chpasswd;usermod -a -G db2iadm1 bluecost;chown -R bluecost:db2iadm1 /home/bluecost/bluecostDB;mkdir /database/data;"
hostname: db2server
privileged: true
ports:
- 50001:50000
- 55000:55000
networks:
- back-tier
volumes:
- ./standalone/linuxScripts/bluecostDB:/home/bluecost/bluecostDB
restart: "no"
env_file:
- ./standalone/db2/.env_list
Here is a shell script that starts db2 and rest of the commands:
docker-compose -f docker-acceptance.yml run -d db2
printf "Waiting for db2 to warm-up *************************\n\n\n\n"
sleep 340
printf "Starting to initialize schema **********************\n\n\n\n"
docker exec -d -t bluecost-db2 /bin/bash -c "cp /home/bluecost`/bluecostDB/*.* /home/db2inst;chmod +x /home/mydir/runBlueCostDBScript.sh;chown db2adm:db2adm /home/db2iadm/*.sql;chown db2adm:db2adm1 /home/db2inst/*.sh;mkdir /database/data/bluecostDB;chown -R db2adm:db2adm1 /database/data/bluecostDB;echo ./runBlueCostDBScript.sh | su - db2adm"`
Notice above that first line in that script runs the db2. That works, the container starts and it warms up, but when the last docker exec command runs, it refers to that container by name 'bluecost-db2' and that container name that's running is sligtly different: bluecost-db2_run1, bluecostdb2_run2, etc
How can I find the exact name to execute? I found this docker ps --format '{{.Image}} {{.Names}}'
but that lists all containers that are running, there may be more than one... how do I get just the name of the db2 container that's running?