0

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?

Navjot Singh
  • 678
  • 7
  • 18
  • 2
    Does this answer your question? [How to stop all containers when one container stops with docker-compose?](https://stackoverflow.com/questions/33799885/how-to-stop-all-containers-when-one-container-stops-with-docker-compose) – Alexey R. Sep 28 '21 at 08:12
  • Editing the question for more details. I was not mentioning a third container which I want to keep running while only wanting to kill selenium container. – Navjot Singh Sep 28 '21 at 08:30
  • @NavjotSingh What's wrong with the third answer of the duplicate? Seems to cover your needs with some minor adjustments. – super Sep 28 '21 at 08:35
  • @super Just edited the question. I want to keep one of the containers alive, so essentially I don't want to stop everything. – Navjot Singh Sep 28 '21 at 08:38
  • @NavjotSingh My comment was in regards to your edit. The third answer shows an approach that would work for you. Just replace `docker-compose stop` with `docker-compose stop selenium`. – super Sep 28 '21 at 08:39
  • @super Wouldn't having a no op command as entry command instantly exit the container? – Navjot Singh Sep 28 '21 at 08:49
  • Yes, that's why you have a `docker-compose run` after it to run the container with the actual command you want. – super Sep 28 '21 at 09:22

1 Answers1

0

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

user2915097
  • 30,758
  • 6
  • 57
  • 59