Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How stop containers run with `docker-compose run`

I'm trying to use docker-compose to orchestrate several containers. To troubleshoot, I frequently end up running bash from within a container by doing:

$ docker-compose run --rm run web bash 

I always try pass the --rm switch so that these containers are removed when I exit the bash session. Sometimes though, they remain, and I see them at the output of docker-compose ps.

           Name                          Command                State      Ports ---------------------------------------------------------------------------------- project_nginx_1            /usr/sbin/nginx                  Exit 0 project_nginx_run_1        bash                             Up         80/tcp project_web_1              python manage.py runserver ...   Exit 128 project_web_run_1          bash                             Up         8000/tcp 

At this point, I am trying to stop and remove these components manually, but I can not manage to do this. I tried:

$ docker-compose stop project_nginx_run_1 No such service: project_nginx_run_1 

I also tried the other commands rm, kill, etc..

What should I do to get rid of these containers?

Edit:

Fixed the output of docker-compose ps.

like image 219
user1496984 Avatar asked Jun 29 '15 03:06

user1496984


People also ask

How do you stop a container run?

To stop one or more running Docker containers, you can use the docker stop command. The syntax is simple: $ docker stop [OPTIONS] CONTAINER [CONTAINER...] You can specify one or more containers to stop.

Does docker compose keep container running?

The docker compose up command aggregates the output of each container (like docker compose logs --follow does). When the command exits, all containers are stopped. Running docker compose up --detach starts the containers in the background and leaves them running.

How do I stop docker runtime?

When you start Docker this way, it runs in the foreground and sends its logs directly to your terminal. To stop Docker when you have started it manually, issue a Ctrl+C in your terminal.

Should I use docker compose down or stop?

The docker-compose stop command will stop your containers, but it won't remove them. The docker-compose down command will stop your containers, but it also removes the stopped containers as well as any networks that were created. You can take down 1 step further and add the -v flag to remove all volumes too.


1 Answers

just stop those test containers with the docker stop command instead of using docker-compose.

docker-compose shines when it comes to start together many containers, but using docker-compose to start containers does not prevent you from using the docker command to do whatever you need to do with individual containers.

docker stop project_nginx_run_1 project_web_run_1  

Also, since you are debugging containers, I suggest to use docker-compose exec <service id> bash to get a shell in a running container. This has the advantage of not starting a new container.

like image 55
Thomasleveil Avatar answered Sep 19 '22 18:09

Thomasleveil