How to stop Docker process from docker hub container busybox? - docker

I don't have any docker containers locally, running them from docker hub.
I ran docker run busybox ping google.com
Then I closed my terminal before stopping the process. Now it seems like I can't stop the process:
➜ ~ docker ps
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
138faab6c40f busybox "ping google.com" 4 minutes ago Up 4 minutes musing_hopper
➜ ~ docker stop busybox
Error response from daemon: No such container: busybox
➜ ~ docker stop busybox
Error response from daemon: No such container: busybox
https://docs.docker.com/engine/reference/commandline/stop/#description
$ docker stop my_container
Also tried
➜ ~ docker kill busybox
Error response from daemon: Cannot kill container: busybox: No such container: busybox

The stop command accepts the container name or id which is different from the image name, which in this case is busybox.
To stop the container, you first need to figure out its name or id, which can be found by running docker container ls and then use the Id or name as input to the stop command:
docker stop <container-name-or-id>

A good command to stop all your running docker containers, in case you closed the terminal before stopping them is:
docker ps -q | xargs docker stop

Related

Cannot stop a docker container

I am very new to docker. I am following a tutorial on it.
I can successfully build and run my docker container.
docker build .
docker run -p 3000:3000 3cd35580990c
But when I try to stop the container
docker stop ef485ea0dabd
Error response from daemon: cannot stop container: ef485ea0dabd: Cannot kill container ef485ea0dabda4939e7cc371408937174bf282a82e169c0fc71c2cf2b0b7bf74: unknown error after kill: runc did not terminate sucessfully: container_linux.go:392: signaling init process caused "permission denied"
: unknown
I got this long error about permission denied.
How can I solve this?
Your stop command is correct if you only want the container to stop. That won't remove the container though. To remove a stopped container you should use
docker container rm <id>
If the container is running (rather than stopped) you can force its removal using
docker container rm -f <id>
You can kill and remove all containers (running and stopped) using this command:
docker container rm -f $(docker ps -qa)
To see what containers you currently have you can use:
docker ps
But that only shows running containers. If you want to see stopped containers too you can do this:
docker ps -qa

Docker: Error response from daemon - why is it not showing in docker container ls?

I have read this post and I have a similar problem :
docker: Error response from daemon: Conflict. The container name "/grafana" is already in use by container "f6b2d471d737a"
and I have the same error. Why is this container not showing, when I type:
docker container ls
is there an option to show all containers ?
To see only running containers:
$ docker container ls
To see all containers:
$ docker container ls -a
-a as in all. You need to use the second command in this situation.

Docker: Only one docker container running when I start two containers from the same container ID

In scenario 1 and 3, two docker containers are running. But in scenario 2, when I start the container with same container ID(twice), I see only one container running. What is the logic/reason behind this?(I was expecting two instances to be running)
SCENARIO 1:
$ docker create busybox ping www.google.com
163a5907dcfd7f37be0debb1153f0307a962a7709aa6c418ddab1f833a3bc4b8
$ docker create busybox ping www.google.com
178c343d16fe7930b78532d234e735f203cad6a7fa3d932d12c71a433922c2b2
$ docker start 163a5907dcfd7f37be0debb1153f0307a962a7709aa6c418ddab1f833a3bc4b8
163a5907dcfd7f37be0debb1153f0307a962a7709aa6c418ddab1f833a3bc4b8
$ docker start 178c343d16fe7930b78532d234e735f203cad6a7fa3d932d12c71a433922c2b2
178c343d16fe7930b78532d234e735f203cad6a7fa3d932d12c71a433922c2b2
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
178c343d16fe busybox "ping www.google.com" About a minute ago Up 11 seconds jovial_maxwell
163a5907dcfd busybox "ping www.google.com" About a minute ago Up 3 seconds relaxed_hofstadter
SCENARIO 2:
$ docker start 163a5907dcfd7f37be0debb1153f0307a962a7709aa6c418ddab1f833a3bc4b8
$ docker start 163a5907dcfd7f37be0debb1153f0307a962a7709aa6c418ddab1f833a3bc4b8
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
163a5907dcfd busybox "ping www.google.com" 3 minutes ago Up 4 seconds relaxed_hofstadter
SCENARIO 3:
$ docker run busybox ping www.google.com
$ docker run busybox ping www.google.com
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a0880fa44941 busybox "ping www.google.com" 6 seconds ago Up 6 seconds xenodochial_bohr
df85aab07d43 busybox "ping www.google.com" 13 seconds ago Up 13 seconds trusting_keldysh
When you run docker create or docker run, a container is created from the given image, it is assigned a unique ID, and that container is run. Thus, if you run the same command twice, you get two containers, each with distinct ID, for the same image and you can run them separately.
When you start a container by its ID, the command applies to that particular container. When you restart it, it will not do anything because that container is already running.

Zombie docker container that can't be killed

I use docker-compose to create a bunch of containers and link them together. For some of the container definitions, I might have restart: always as the restart policy.
Now I have a postgres container that respawns back to life if stopped.
$docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a8bb2b781630 postgres:latest "docker-entrypoint.s…" About an hour ago Up About an hour 5432/tcp dcat_postgres.1.z3pyl24kiq2n4clt0ua77nfx5
docker stop a8bb2b781630
a8bb2b781630
$ docker rm -f a8bb2b781630
a8bb2b781630
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
93fa7b72c2ca postgres:latest "docker-entrypoint.s…" 12 seconds ago Up 4 seconds 5432/tcp dcat_postgres.1.oucuo5zg3y9ws3p7jvlfztflb
Using docker-compose down in the dir that started the service doesn't work either.
$ docker-compose down
Removing dcat_postgres_1 ... done
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7ee7fb0e98cd postgres:latest "docker-entrypoint.s…" 13 seconds ago Up 5 seconds 5432/tcp dcat_postgres.1.jhv1q6vns1avakqjxdusmbb78
How can I kill a container and keep it from coming back to life?
EDIT: The container respawns even after restarting the Docker service.
Docker - 18.06.1-ce-mac73 (26764)
macOS High-Sierra, (10.13.6)
I figured it out. Turns out it was related to docker swarm. I had experimented with it at some point without fully understanding what it is and what it does and apparently it just stayed there.
All I had to do was:
docker swarm leave --force
and it worked like a head-shot to an actual zombie.
Can you try an option like moby/moby issue 10032:
docker stop $(docker ps -a -q) &
docker update --restart=no $(docker ps -a -q) &
systemctl restart docker
(this assume here you have only one running container: the one you cannot prevent to start)
A docker rm -f should be enough though, unless you are using docker with a provision tool like Puppet.
As it turned out, another process (other than docker itself) was responsible for the container to restart (here docker swarm)
Update 2020/2021: For multiple containers, possibly without having to restart the docker daemon
docker ps -a --format="{{.ID}}" | \
xargs docker update --restart=no | \
xargs docker stop
Check if you need, as in the issue, remove the images as well ( | xargs docker rmi $(docker images -qa) --force)

How to bring a running docker container again foreground

I have a docker container running
sudo docker ps -a
result:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0cd8d5166717 32bit/ubuntu:14.04 /bin/bash 15 hours ago Up About an hour hadoop-test
How can I bring this running container again to -it mode and grab the terminal of ubuntu system ?
You can attach it:
docker attach 0cd8d5166717
Type Ctrl-PCtrl-Q to detach it again.

Resources