Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill container generated by docker-compose?

(sorry using the term "kill" with quotes is not about docker-compose kill, is about "UNIX ps kill" after what the process really go out of the "UNIX ps list")


Usual docker run can be "killed" by usual docker stop, because after stop I not see the container at docker ps -a... If it is correct, there are a semantic bug with docker-compose because I can't "kill" the containers, they stay at docker ps.

After my simple docker-compose up (without &) I do ^C and the containers stay there at docker ps -a... Impossible to kill by docker compose stop.


NOTE: when I use ordinary docker run and after it docker stop there are nothing at docker ps -a, so I can say "I killed it".

like image 914
Peter Krauss Avatar asked Jul 25 '18 11:07

Peter Krauss


2 Answers

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.

like image 77
tgogos Avatar answered Oct 18 '22 02:10

tgogos


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

like image 33
emix Avatar answered Oct 18 '22 02:10

emix