What are the extra containers removed by "docker container prune" not listed by "docker ps -a"? - docker

~/tmp/Counter1 ⌚ 10:18:24
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a46d397337e6 xx "echo ls" 20 hours ago Exited (0) 20 hours ago cranky_snyder
28d7339e57aa bf3a41a4ae8f "/bin/sh -c 'echo $e…" 21 hours ago Exited (0) 21 hours ago unruffled_archimedes
~/tmp/Counter1 ⌚ 10:18:27
$ docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
a46d397337e68101fe983f354f87e8b4c0e086a4157dce7e7c4a2558105da525
28d7339e57aa222697851aaf4fdd36da2cbbc16f5fa9d4373ac499f8f8e15de5
a3cf99470e2f6e623c97db14249fa14e0afe9fd01eaac1ef6087ef98575f3690
5123adaa9fab02346c589aa23d3dd1eae1085138ec0e9cb23f388bbc5d668a92
45727d359ea4a036dd466f72fbaa750b135244d730b514c63a96518c71b4ad90
3260c4155074df32038ee31273e7059c1755fe6145b98d187ca006e1a39c3636
7d9c83d179932b1c97d43077cfe19fb6bcac123e295affcfa4cc791c43ddf513
3e32ee26e2e91ffc704cb27069cddf8f2f576ca407b4d8969e528c5a229cd855
46e8782774e2a6d5c8885fa5710134e1cc26e4abd75f29d883e4b32abec07d82
4728995a0162a033869e9fdd306435b1365309da643b2bcfa708c04839e7993c
Total reclaimed space: 0B
If I repeat the same thing, I see the right number of docker container removed. But after some time of playing with more containers, I again see a similar mismatch in the number of containers.
If I understand correctly, docker ps -a should show me all containers. Wonder what the other SHAs are from?

Related

How to restart my Docker container?

This is what ps -a gives us
NAMES
4514ea1b7b22 debian "--name gallant_spen…" 9 minutes ago Created peaceful_engelbart
df9bd2731a2b debian "--name gallant_spen…" 9 minutes ago Created happy_hodgkin
dd5b1f1b39ec redis "docker-entrypoint.s…" 32 minutes ago Up 31 minutes 6379/tcp myred
ffd6ef9d8bd5 redis "docker-entrypoint.s…" 32 minutes ago Exited (127) 32 minutes ago festive_jennings
9d01d321adad redis "docker-entrypoint.s…" 33 minutes ago Exited (0) 32 minutes ago agitated_shannon
eb7c13e7cdee debian "ls /data" 2 days ago Exited (0) 9 seconds ago gallant_spence
8991a31b1e38 debian "ls /data" 2 days ago Exited (0) 2 days ago determined_minsky
I have tried in this manner
docker start `docker ps -q -l` gallant_spence
But error ocurrs
Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"--name\": executable file not found in $PATH": unknown
gallant_spence
Error: failed to start containers: 4514ea1b7b22
I am interested in data volume that has been mounted in my previous work on this container
"Mounts": [
{
"Type": "bind",
"Source": "/home/mm/code/lesson_04",
"Destination": "/data",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
If I try
mm#6830s:~$ docker start -ai gallant_spence
one_sample.py
parallel_series.py
Python files are added to data folder so I thought that it worked.Then I try again
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd5b1f1b39ec redis "docker-entrypoint.s…" About an hour ago Up About an hour 6379/tcp myred
Hot to fix this?
You start a stopped container with
docker start [OPTIONS] CONTAINER [CONTAINER...]
For your case, you can use:
docker start gallant_spence or
docker start eb7c13e7cdee
As it is shown by the docker ps -a result, your container is configured with this CMD:
"ls /data"
This means that every time you start your container, this command will run and the container will then exit. This is how containers work. When their primary process finishes, they exit.
About the error you get and docker ps -q -l:
-q (from "quiet") tells the command to only print the container IDs
-l (from "last") tells the command to print the latest created container
This means that the above command brings you back: 4514ea1b7b22. If we put together all things...
your command:
docker start `docker ps -q -l` gallant_spence
turns to:
docker start 4514ea1b7b22 gallant_spence
The fail message you get is for 4514ea1b7b22 because it doesn't have a CMD set properly to start. I see something like: --name gallant_spen…

Why does the name column of the docker ps -a always different

I was just playing around with docker!!
Ran ps command -a option
docker run -a
C:\Users\sarkan1>docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3d6db385321c busybox:1.24 "sleep 1000" 26 seconds ago Up 24 seconds lucid_ramanujan
e6acd65398b2 hello-world "/hello" 43 minutes ago Exited (0) 43 minutes ago nifty_brattain
c5576137580d hello-world "/hello" 4 days ago Exited (0) 4 days ago dreamy_aryabhata
2594fbf1fa82 hello-world "/hello" 4 days ago Exited (0) 4 days ago nostalgic_hopper
c0102bc64c45 hello-world "/hello" 4 days ago Exited (0) 4 days ago vibrant_khorana
c4af79ea96e9 hello-world "/hello" 4 days ago Exited (0) 4 days ago cranky_heyrovsky
Questions :
Why did I get the values in the names column always different? I ran the same container I guess!!
What is command column? Does the slash before the hello (/hello) have any significance?
Unless you launch a container specifying its name (docker run --name), docker will generate one for you.
That is easier than referencing said container with its ID.
You can then make docker commands with its (generated) name instead.
See more at "How does Docker generate default container names?".
(and the source code: moby/moby pkg/namesgenerator/names-generator.go)
The command column is the full command executed by the container: once this command stops, the container stops.
That command is specified in the docker image, and is a combination of:
Dockerfile ENTRYPOINT
Dockerfile CMD
(See "difference between cmd and entrypoint in dockefile")
Basically they are random container names generated!! The left and right parts of the names are hardcoded and can be found in
https://github.com/moby/moby/blob/master/pkg/namesgenerator/names-generator.go
Docker engine generates it if default name is not provided when you create a new docker container.

See docker containers that are not in k8s

docker ps command give's a list of all containers running on machine.
Containers started by kubernetes, docker-compose or using docker commands.
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4522aaa65d4b gcr.io/kube-addon-manager:v6.4-beta.1 "/opt/kube-addons.sh" 39 hours ago Up 39 hours k8s_kube-addon-manager.....
88b141f545d3 gcr.io/pause-amd64:3.0 "/pause" 39 hours ago Up 39 hours k8s_POD.....
fe39bcdf10c0 celery "/usr/local/bin/celer" 39 hours ago Up 39 hours celery_worker
I would like to see all containers that are not started by kubernetes.
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe39bcdf10c0 celery "/usr/local/bin/celer" 39 hours ago Up 39 hours celery_worker
it's about as simple as docker ps | grep -v 'k8s_'

deleting old images in Docker - OSX

I've been toying with a docker image for Tensorflow.
To summarize, I first installed the standard image, then realized I needed nodejs, so added it and did a docker commit. Then realized I needed expressJS, added it an did a commit
I am running docker v1.12.5 (so the new gc/prune commands are not there)
At this stage, docker images -a shows:
REPOSITORY TAG IMAGE ID CREATED SIZE
tensor-node-express latest f2f59eb61aae 15 hours ago 2.104 GB
gcr.io/tensorflow/tensorflow latest-devel 308238445d5c 2 days ago 1.995 GB
gcr.io/tensorflow/tensorflow <none> 74435614a991 9 days ago 1.52 GB
I only want to keep tensor-node-express and delete the older images.
$ docker rmi 308238445d5c
Error response from daemon: conflict: unable to delete 308238445d5c (cannot be forced) - image has dependent child images
$docker rmi gcr.io/tensorflow/tensorflow:latest-devel
Error response from daemon: conflict: unable to remove repository reference "gcr.io/tensorflow/tensorflow:latest-devel" (must force) - container 03de9d864e31 is using its referenced image 308238445d5c
I assumed that this means docker commits store differential images, but when I go to ~/.docker/machine/machines/default, I see:
40894464 Mar 13 13:57 boot2docker.iso
5043847168 Mar 16 08:34 disk.vmdk
I suppose the 5G file is a composite of my images, which seems to show each docker commit is the full image!
Any thoughts on how I can only use the latest docker image (tensor-node-express) and free my HD of the invasion of docker?
Supplementary info - here is the output of docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e6dcd2915991 tensor-node-express "/bin/bash" 15 hours ago Exited (130) 15 hours ago flamboyant_bose
fb44b19a21c2 gcr.io/tensorflow/tensorflow:latest-devel "/bin/bash" 18 hours ago Exited (130) 15 hours ago compassionate_bose
075001a687e3 gcr.io/tensorflow/tensorflow:latest-devel "/bin/bash" 18 hours ago Exited (0) 18 hours ago nervous_sinoussi
a80ce2d2e688 gcr.io/tensorflow/tensorflow:latest-devel "/bin/bash" 19 hours ago Exited (130) 18 hours ago happy_euclid
f493bd3c8712 gcr.io/tensorflow/tensorflow:latest-devel "/bin/bash" 19 hours ago Exited (1) 19 hours ago friendly_cori
03de9d864e31 gcr.io/tensorflow/tensorflow:latest-devel "/bin/bash" 2 days ago Exited (255) 23 minutes ago 6006/tcp, 8888/tcp tender_hopper
2dd1e83d62d3 gcr.io/tensorflow/tensorflow:latest-devel "/bin/bash" 2 days ago Exited (0) 15 hours ago modest_einstein
3067ed171b1c gcr.io/tensorflow/tensorflow:latest-devel "/bin/bash" 2 days ago Exited (0) 2 days ago dazzling_bhabha
62c699afd3fd 74435614a991 "/bin/bash" 2 days ago Exited (127) 2 days ago inspiring_austin
9523ffe2945c 74435614a991 "/bin/bash" 2 days ago Exited (0) 2 days ago kickass_leakey
e06958ea517c 74435614a991 "/bin/bash" 2 days ago Exited (0) 2 days ago objective_euler
ccf922954667 74435614a991 "/bin/bash" 2 days ago Exited (255) 2 days ago dreamy_bartik
fad0d92a07a3 74435614a991 "/bin/bash" 2 days ago Exited (130) 2 days ago elastic_dubinsky
f2a98d4e11ea 74435614a991 "/bin/bash" 2 days ago Exited (0) 2 days ago heuristic_kilby
f07e46367b17 74435614a991 "/bin/bash" 2 days ago Exited (130) 2 days ago trusting_darwin
5bbf9cf992b8 74435614a991 "/bin/bash" 2 days ago Exited (0) 2 days ago flamboyant_knuth
I tried
docker ps --filter "status=exited" | grep "days ago" | awk '{print $1}' | xargs docker rm (credit)
I ran the above manually as well for some of the containers it missed
That pruned the ps list to:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e6dcd2915991 tensor-node-express "/bin/bash" 15 hours ago Exited (130) 15 hours ago flamboyant_bose
But even then I can't delete old images - same error.
Further update, I tried to list dependencies in images (credit)
using this script:
for i in $(docker images -q)
do
docker history $i | grep -q 74435614a991 && echo $i
done | sort -u
And it told me:
308238445d5c
74435614a991
f2f59eb61aae
This means my new images are child images of the old image. But the size is not a differential looking at the disk size.
Thoughts?
docker-machine uses a Linux VM
When you looked at the docker-machine .vdmk and .iso files, what you are looking at is files for a Linux VM running on your Mac. This is needed because Docker requires Linux kernel features to run, it cannot run directly on the Mac's microkernel.
So your Mac is running a Linux virtual machine, and inside that virutal machine is running the Docker daemon and all of your containers.
Therefore the file size of the .vmdk and .iso tell you nothing about any one image.
docker images have parent/child relationships
As you may already know, docker images have parents and/or children. For instance when you build an image with a Dockerfile like this:
FROM ubuntu:latest
RUN apt-get update && apt-get install nginx
You will end up with a new image that you have perhaps tagged my-nginx. But it requires the ubuntu:latest image as its parent; you cannot delete ubuntu:latest with this image still around, as it requires its parent.
docker commit creates those relationships
When you use docker commit, you are basically doing a dynamic snapshot build. It is similar to the above, except there's no Dockerfile involved.
The above example has a FROM line which indicates the image to use as a base. When using commit, there is a base implied - whatever image was used to launch the running container that you are committing.
The above example has a RUN command which will create new contents in the built image, above and beyond the base image. In a real Dockerfile there are usually multiple commands that do various things which build on the base image. When you use commit, you don't have that. Instead, anything that has been written to the container on top of the base image is your new content. It exists in a read-write filesystem layer in the container. That is the thing you are committing; it is written as a new read-only layer and you get that back as a new (immutable, read-only) docker image. With a parent.
Based on your comments, and the question itself, you appear to have believed that using docker commit would create a new full image that had no dependencies on other images. That is not true. You can craft images like that if you build them yourself from scratch, just not this way.
You can untag the image
If what you want is for the image to not show up in your list, that's easy. Just untag it.
docker rmi gcr.io/tensorflow/tensorflow:latest-devel
However, this is more or less cosmetic. The image will still be there, as another image requires it. All this does is remove the tag, so it doesn't appear in the docker images list anymore without the -a flag.
The reason trying this did not work for you is you tried to rmi the image using its ID, not using its tag.

I run a docker container,but after few minutes , it was killed by himself

I have run a docker container and using nsenter into it.But after few minutes,this container was killed by himself
root#n14:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e69069513c8b sameersbn/mysql "/start" 25 minutes ago Up 12 seconds 3306/tcp mysqldb1
02f3f156b3e7 sameersbn/mysql "/start" 25 minutes ago Up 25 minutes 3306/tcp mysqldb
root#n14:~# nsenter --target 13823 --mount --uts --ipc --net --pid
root#e69069513c8b:/home/git/gitlab# Killed
root#n14:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e69069513c8b sameersbn/mysql "/start" 55 minutes ago Exited (0) 28 minutes ago mysqldb1

Resources