This question already has answers here:
Stop and remove all docker containers
(12 answers)
Closed 10 months ago.
I want running containers to be stopped and removed.
PS C:\Users\Bayram Eren> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8d8299ddb6bf nginx "/docker-entrypoint.…" 8 minutes ago Up 8 minutes 80/tcp con1
554971502a96 nginx:latest "/docker-entrypoint.…" 17 minutes ago Up 17 minutes 80/tcp goofy_goldberg
PS C:\Users\Bayram Eren>
Docker container prune -f
Total reclaimed space: 0B
returns result
Why is this happening
You have to stop your containers before removing them:
docker stop 8d8299ddb6bf
docker stop 554971502a96
Or you can stop all running containers in one command
docker stop $(docker ps -q -f status=running)
Then you can call
docker container prune -f
Related
I run docker ps and it shows that 5 containers that have been running for three weeks.
I then run docker-compose down but when I run docker ps again, they are all still running.
I have tried the following command but none seems to work
kill
stop
down --rmi local
rm
down
How can I stop these? I tried just bringing up my new docker-compose.yml and ignoring the olde one but I get:
ERROR: for apache Cannot create container for service apache: Conflict. The container name "/apache" is already in use by container "70c570d60e1248292f279a37634fd8b4ce7e2535d2bfa14b2c6e4089652c0152". You have to remove (or rename) that container to be able to reuse that name.
What to try to stop the old container?
You can list containers:
(base) docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c788727f0f7b postgres:14 "docker-entrypoint.s…" 7 days ago Up 7 days 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp dev-db
88e8ddcb7d4e redis "docker-entrypoint.s…" 7 days ago Up 7 days 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp beautiful_neumann
Delete container:
(base) docker rm -f c788727f0f7b # container_id
c788727f0f7b
List containers:
(base) docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
88e8ddcb7d4e redis "docker-entrypoint.s…" 7 days ago Up 7 days 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp beautiful_neumann
As you can see the container got stopped(c788727f0f7b).
You can list stopped containers using:
docker container ls -f 'status=exited'
I tried to start a container output as follows,
I have listed all available containers using docker ps --all.
[root#sdctlt0048 express_edition]# docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ceb4b5256c32 store/saplabs/hanaexpress:2.00.045.00.20200121.1 "/run_hana --passwor…" 6 hours ago Exited (1) 3 hours ago express_edition
7d838bf619df 389fef711851 "echo hello" 4 days ago Exited (0) 4 days ago helloWorld
b743cad7815f portainer/portainer-ce "/portainer" 2 weeks ago Up 2 weeks 0.0.0.0:8000->8000/tcp, 0.0.0.0:9000->9000/tcp portainer
47cc21a338dd portainer/portainer "/portainer" 2 weeks ago Exited (1) 2 weeks ago youthful_maxwell
97e277d42155 hello-world "/hello" 2 weeks ago Exited (0) 2 weeks ago confident_roentgen
I entered the following commands to start the container which is in the exit stage and enter the terminal of this image.
docker start ceb4b5256c32
docker exec -it ceb4b5256c32 bach
It throws the following error.
FATA [0000] Error response from daemon: Container ceb4b5256c32 is not running
But when I start the container using docker start ceb4b5256c32. It throws the container ID out, which is okay if everything is working normally. I am not sure what caused this error.
for my docker run i was created a script where I put all my commands as follows:
Any idea on the causes and suggestions on this would be very helpful to me.
many Thank in advance.
Mb the container has already stopped when you want to execute the command?
Check if conatainer have a status Exited and logs
docker ps | grep ceb4b5256c32
docker logs ceb4b5256c32 --tail 5
If the container always stops and this is normal then try it (--rm - remove container after stopped):
docker run --rm -it <image:name> <command>
Eg:
# ~ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# ~ docker run --rm -it debian bash
root#22ce8b31b68c:/# exit
exit
# ~ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# ~
Using an image from https://hub.docker.com/_/php.
Create and launch a hogehoge-php container with docker run -dti
% docker run -dti --name hogehoge-php php
Then I can see that the hogehoge-php container is up and running.
confirmed:
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2c9e7ff1a952 php "docker-php-entrypoi..." 6 seconds ago Up 5 seconds ago hogehoge-php
try with pull, create and start
I read that the docker run is a command that performs docker pull, docker create, and docker start all at once. So I decided to try it out as follows (I didn't do the docker pull because I already have a local php image).
% docker create --name foofoo-php php
c7687c088dda9b71d9380e9ca472afa436ac63785c1d2c195b8a08147f8adec9
% docker start foofoo-php
foofoo-php
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7687c088dda php "docker-php-entrypoi..." 16 seconds ago Exited (0) 3 seconds ago foofoo-php
When I tried as above, I got Exited (0) 3 seconds ago, and the foofoo-php container created by docker create doesn't stand up all the time.
The foofoo-php container made by docker create doesn't stand up(options not available).
% docker start -dti foofoo-php
unknown shorthand flag: 'd' in -dti
See 'docker start --help'.
The i option is available, and I was able to run it, but it doesn't leave the docker running.
% docker start -i foofoo-php
Interactive shell
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7687c088dda php "docker-php-entrypoi..." 3 minutes ago Exited (0) 5 seconds ago foofoo-php
How can I create and start instead of run -dti?
By the way, I tried docker run without -dti
By the way, I tried docker run without -dti.
% docker run --name barbarbar-php php
Interactive shell
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6215c71a13a4 php "docker-php-entrypoi..." 15 seconds ago Exited (0) 15 seconds ago barbar-php
The container was created, but it's not standing up. I thought I should try docker start:
% docker start barbar-php
barbar-php
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6215c71a13a4 php "docker-php-entrypoi…" 33 seconds ago Exited (0) 3 seconds ago barbar-php
but the container doesn't start up.
On the other hand, stop and start a container created by docker run -dti
On the other hand, try to stop and start a container created by docker run -dti, it running up after start.
% docker stop hogehoge-php
hogehoge-php
% docker start hogehoge-php
hogehoge-php
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6215c71a13a4 php "docker-php-entrypoi…" 4 minutes ago Exited (0) About a minute ago barbar-php
c7687c088dda php "docker-php-entrypoi…" 11 minutes ago Exited (0) 8 minutes ago foofoo-php
2c9e7ff1a952 php "docker-php-entrypoi…" 14 minutes ago Up 2 seconds hogehoge-php <----- Here
Behavior Summary
docker run
with dit option
up after a run
up after start
without dit option
not up after a run
not up after a start
docker create
not up after a run
What you are missing is a docker create -t to allocate a pseudo-TTY for you container.
Since the entrypoint for the image you are running is a php shell running at the foreground, the container, when started, figures out that it doesn't have a tty to attach to an exit with 0.
docker pull php
docker create -t --name hogehoge-php php
docker start hogehoge-php
I haven't found any indication about how to completely restart hyperledger fabric and all the docker containers after rebooting the computer.
In particular, I have this containers:
$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8fe26f6bf531 hyperledger/fabric-peer:1.2.1 "peer node start" 41 minutes ago Up 40 minutes 0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp peer0.org1.example.com
0caca897250f hyperledger/fabric-orderer:1.2.1 "orderer" 41 minutes ago Up 40 minutes 0.0.0.0:7050->7050/tcp orderer.example.com
a3addacf7808 hyperledger/fabric-couchdb:0.4.10 "tini -- /docker-ent…" 41 minutes ago Up 41 minutes 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp couchdb
1c699bc55cbf hyperledger/fabric-ca:1.2.1 "sh -c 'fabric-ca-se…" 41 minutes ago Up 41 minutes 0.0.0.0:7054->7054/tcp ca.org1.example.com
a3214a02a0e5 localhost/composer-rest-server "pm2-docker composer…" 17 hours ago Exited (0) 17 hours ago rest
30c1e5ace414 mongo "docker-entrypoint.s…" 17 hours ago Exited (0) 17 hours ago mongo
b7baef0aa3c7 dev-peer0.org1.example.com-tutorial-network-0.0.1-6695b9314667cc296171c0da511644e9011aa9a3ba0f6e759aca9e32e458803c "/bin/sh -c 'cd /usr…" 17 hours ago Exited (0) 17 hours ago dev-peer0.org1.example.com-tutorial-network-0.0.1
running the command ./startFabric.sh only the first four containers are started.
How can I restart also the last three containers to have a system running like before rebooting?
Possibly ./stopFabric followed by ./teardownFabric before using ./startFabric?
As far as I see, u r working on windows, in order to restart ur docker and network, u can't use simple commands like in Ubuntu, before restarting ur docker containers, stop all running containers, remove them, prune the volume of docker, then restart ur docker, finally, u can re-run the Hyperledger Network:
1)Stop running containers, remove them, prune volume:
$docker stop $(docker ps -a -q)
$docker rm $(docker ps -a -q)
$docker volume prune
2)Restart ur docker, for this go to the docker icon on the right bottom of the desktop, right click, then "restart":
3)Finally, re-run the network:
$./startFabric.sh
!!!=>Solution for the Ubuntu case:
$docker stop $(docker ps -a -q)
$docker ps -qa|xargs docker rm
$sudo systemctl daemon-reload
$sudo systemctl restart docker
$./startFabric.sh
Yes, its very well the case that your network i stopped just because some of the containers exited. Now to fully recover the whole thing just use ./stopFabric.sh and then check if all containers are deleted by using
docker ps -a
Then you can again start your network by using ./startFabric.sh and then check if all the containers are working fine by using
docker ps -a
On my remote server, some developers run the same docker images named "my_account/analysis". So, once detached from the docker process, it is struggling to know which is my own process.
The result of docker ps is like this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6968e76b3746 my_account/analysis "bash" 44 hours ago Up 44 hours 6023/tcp, 6073/tcp, 6800/tcp, 8118/tcp, 8888/tcp, 9050/tcp, 0.0.0.0:8887->8887/tcp modest_jones
42d970206a29 my_account/analysis "bash" 7 days ago Up 7 days 6023/tcp, 6073/tcp, 6800/tcp, 8118/tcp, 8888/tcp, 9050/tcp, 0.0.0.0:32771->8885/tcp gallant_chandrasekhar
ac9f804b7fe0 my_account/analysis "bash" 11 days ago Up 11 days 6023/tcp, 6073/tcp, 6800/tcp, 8118/tcp, 8888/tcp, 9050/tcp, 0.0.0.0:8798->8798/tcp suspicious_mayer
e8e260aab4fb my_account/analysis "bash" 12 days ago Up 12 days 6023/tcp, 6073/tcp, 6800/tcp, 8118/tcp, 8888/tcp, 9050/tcp, 0.0.0.0:32770->8885/tcp nostalgic_euler
In this case, because I remember that I ran docker around 2 days ago, I attach my container by docker attach 6968e. However, usually we forgot this.
What is the best practice to detect the container ID of mine under the situation that there are a lot of containers with the same Image name?
The simple way is to name the containers
docker run --name my-special-container my_account/analysis
docker attach my-special-container
You can store the container ID in a file when it launches
docker run --cidfile ~/my-special-container my_account/analysis
docker attach $(cat ~/my-special-container)
You can add more detailed metadata with object labels, but they are not as easily accessible as names
docker run --label com.rkjt50r983.tag=special my_account/analysis
docker ps --filter 'label=com.rkjt50r983.tag=special'