I am using docker-compose version 2. I am starting containers with docker-compose -p some_name up -d
and trying to kill them with docker-compose stop
. The commands exits with 0
code but the containers are still up and running.
Is this the expected behaviour for version? If yes, any idea how can I work around it?
my docker-compose.yml
file looks like this
version: '2'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:5.3.0
ports:
- "9200:9200"
environment:
ES_JAVA_OPTS: "-Xmx512m -Xms512m"
xpack.security.enabled: "false"
xpack.monitoring.enabled: "false"
xpack.graph.enabled: "false"
xpack.watcher.enabled: "false"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 262144
hard: 262144
kafka-server:
image: spotify/kafka
environment:
- TOPICS=my-topic
ports:
- "9092:9092"
test:
build: .
depends_on:
- elasticsearch
- kafka-server
update
I found that the problem is caused by using the -p
parameter and giving explicit prefix to the container. Still looking for the best way to solve it.
To stop a docker application that is running in the foreground, you just have to press Ctrl-C as show above. But, to stop a docker application that is running in the background, use the docker-compose stop as shown below.
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.
Kill All Containers Using Docker Compose If you do, killing multiple containers takes one command: docker-compose down. You could also run docker-compose without detached mode. If so, you'll just use ^C to kill all containers. And there you have it—all containers killed!
Networks and volumes defined as external are never removed. Anonymous volumes are not removed by default.
docker-compose -p [project_name] stop
worked in my case. I had the same problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With