I have three docker containers. First container is a Wordpress container which starts a wordpress instance. Second container is a selenium server container created from selenium/standalone-chrome image which is supposed to do some initial setup of the wordpress via UI interactions. I have a python script that has all the commands to send to the selenium server. I am running this script in a python container as the third container. All the containers are spawned using docker-compose and are in the same network, so that communication can happen.
Once the python container is finished running the script it exits, however the selenium server and the wordpress container keep running. Once I am done with the script, I want to stop the selenium server container as well but keep the wordpress container running.
I had a thought to run a script inside the python container as entrypoint which first executes the script and then issues a command to stop the other container but for that I guess the python container should also have docker available inside it. So, I think this will not work. Is there a simple way to achieve this?
The command
docker ps --filter=name='my-container'
will show you if the interesting container is still here
example
docker ps
shows many containers
but you can filter
docker ps --filter=name='cadvisor'                                                                                                                                     CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                    NAMES 984f35929991        google/cadvisor              "/usr/bin/cadvisor -…"   3 years ago         Up 2 hours          0.0.0.0:1234->8080/tcp   cadvisor
`
and so a script can test the presence of both containers, only one, and do a
docker stop xxx
when needed
Is it possible to stop a docker container after other docker container inside the same network exits?