How stop containers run with `docker-compose run`

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.


With docker-compose, services can be stopped in two ways, but I would like add some detailed info about both options.

In short

docker-compose down

Stop and remove containers, networks, images, and volumes

docker-compose stop

Stop services


In detail

If docker-compose run starts services project_nginx_run_1 and project_web_run_1, then

docker-compose down log will be

$ docker-compose down
Stopping project_nginx_run_1 ...
Stopping project_web_run_1 ...

.
. some service logs goes here

Stopping project_web_run_1 ... done
Stopping project_nginx_run_1 ... done
Removing project_web_run_1 ... done
Removing project_nginx_run_1 ... done
Removing network project_default

docker-compose stop log will be

$ docker-compose stop
Stopping project_nginx_run_1 ...
Stopping project_web_run_1 ...

.
. some service logs goes here

Stopping project_web_run_1 ... done
Stopping project_nginx_run_1 ... done

The docker-compose, unlike docker, use the names for it's containers defined in the yml file. Therefore, to stop just one container the command will be:

docker-compose stop nginx_run