How to kill container generated by docker-compose?

Check out running containers:

docker ps

Example output:

CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                              NAMES
e86521d81a96        app_php                 "docker-php-entrypoi…"   2 hours ago         Up About an hour    0.0.0.0:8080->80/tcp               app_php_1
7a30681b6255        mysql:5.6               "docker-entrypoint.s…"   3 hours ago         Up About an hour    0.0.0.0:3306->3306/tcp             app_db_1
21aa3eef5f42        phpmyadmin/phpmyadmin   "/run.sh supervisord…"   4 hours ago         Up About an hour    9000/tcp, 0.0.0.0:8081->80/tcp     app_phpmyadmin_1
9afc52b3f82f        mailhog/mailhog         "MailHog"                4 hours ago         Up About an hour    1025/tcp, 0.0.0.0:8082->8025/tcp   app_mailhog_1

then stop one by the container id:

docker kill part_of_the_id/name

For instance:

docker kill e86 or docker kill app_php_1

Docker-compose is just a script to help you manage one or multiple containers running in a group and is absolutely not required to manage your containers.

To remove the container completely you have to remove the container docker rm container_id_or_name

To stop all running containers:

docker stop $(docker ps -q)

Usual docker run can be "killed" by usual docker stop, because after stop I not see the container at docker ps.

No. docker stop just stops a running container, it doesn' t remove the container. This happens only in case you've used docker run --rm .... This --rm option means that when the container is stopped, it will be removed/deleted.


Docker

  • docker run ... creates and runs a container
  • docker stop ... stops a running container
  • docker start ... starts a stopped container
  • docker rm ... removes a stopped container

Docker Compose

  • docker-compose up creates and runs a collection of containers
  • docker-compose stop stops the containers
  • docker-compose start starts the containers
  • docker-compose down stops and removes the containers

Be careful...

As it discussed in the comments section, by using docker-compose down other things can also take place regarding volumes, networks. Keep in mind that you might lose data (if your container is a database for example) and make sure you have saved them or you are somehow able to create them again.