docker image ls
(displays list of images available on this machine)
(or simply docker images instead of docker image ls)
docker image ls -a
(displays list of all images. I think it includes deleted images? intermediate images?)
docker rmi ==> will remove the image.
docker container ls
(displays all containers currently running)
(or simply docker ls)
docker container ls -a
(displays all containers including those stopped, exited)
(Question – can we restart a container?)
(Question – can we delete an image and still container be running?)
docker rm ==> will remove the container.
Image Vs Container
This link is good.
An image is an inert, immutable, file that’s essentially a snapshot of a container. Images are created with the build command, and they’ll produce a container when started with run. Images are stored in a Docker registry such as registry.hub.docker.com. Because they can become quite large, images are designed to be composed of layers of other images, allowing a miminal amount of data to be sent when transferring images over the network.
‘docker history’ is your friend
docker history command is your friend. It gives complete history of all the layers an image is built on including the size of each layer.
docker inspect is second best friend
docker inspect is awesome! It gives everything you need to know for a container.
Digging inside docker container
- docker attach (is one way)
To detach try Ctrl + P / Ctrl + Q
If it doesn’t work – try to kill the process which is attached. (
pkill -9 -f 'docker.*attach')
2. docker container exec
e.g.. docker container exec 76192e17722e cd bin && ls
This is another cool command. It makes a new docker image from running container. Take it to new machine and start running; or use it for debugging, Use the image to start container with additional options.
Looks like this is similar to docker history for image ;
Helpful tips for debugging container issues
- docker container exec <run any command like ps, top, ls>
- docker container exec -it <id> bash
- docker container exec -it -u 0 <id> bash
- docker container logs << Must run after you start a container>>
- docker container stats << view memory/CPU usage>>
- docker container top
- docker cp
- docker diff
- docker export (Gets all files as tar)
- docker container prune ==> removes all stopped containers.
- docker image prune
- docker system df
- docker system prune (My favorite)
- docker rm $(docker ps -aq -f status=exited)
- This link is good.
Another doc link from docker to understand more about images vs containers.