Penguin, small TECH.BARWICK.DE
Docker
 

Recent posts

Categories

Archive

Syndication

 



Powered By

Info

Docker cheatsheet

Installation

Use the Docker repositories to obtain the most up-to-date version:

Images

Obtaining images

Executing e.g. docker run centos will download the specified image.

Listing images

List locally available images:

$ docker images
REPOSITORY     TAG       IMAGE ID       CREATED         SIZE
debian         10        5890f8ba95f6   4 weeks ago     114MB
debian         latest    5890f8ba95f6   4 weeks ago     114MB
ubuntu         latest    f63181f19b2f   6 weeks ago     72.9MB
centos         7         8652b9f0cb4c   3 months ago    204MB
hello-world    latest    bf756fb1ae65   14 months ago   13.3kB

List image IDs only (useful for bulk operations, see below):

$ docker images -q
ff9735b37ed6
8652b9f0cb4c
f1a218c25b76
e76f637b44b7

To filter images by name, use the --filter reference=... option, e.g.:

$ docker image ls --filter "reference=hello*"
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    bf756fb1ae65   14 months ago   13.3kB

Show image details

Execute docker inspect $image_id, e.g.:

$ docker inspect 448f22f1582f
[
    {
        "Id": "448f22f1582fa9f9cb8810b13d9360f29e55e6f90a6b40ebf93d0b17d5df8b63",
        "Created": "2021-03-10T07:17:51.119901148Z",
        "Path": "/sbin/init",
        "Args": [
            "--system"
        ],
...
] 

Removing images

Execute docker rmi $image_id, e.g.:

$ docker rmi 03b52c782013
Untagged: container_test:0.1
Deleted: sha256:03b52c7820130b5cee698db172030e4bbaa99b600c706d9ef124f131104c81d3

If an image is in use by a container (whether stopped or running), it can only be removed with the --force option, e.g.:

$ docker image rmi $(docker image ls -q --filter "reference=hello-world")
Error response from daemon: conflict: unable to delete bf756fb1ae65 (must be forced) - image is being used by stopped container 3df2b5bf49da

$ docker image rmi $(docker image ls -q --filter "reference=hello-world") --force
Untagged: hello-world:latest
Untagged: hello-world@sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b

Containers

A container is an instance of a Docker image which can be executed using the Docker run command.

List running containers

Running containers and their details can be listed with docker ps or docker container ls, e.g.:

$ docker container ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED        STATUS        PORTS                        NAMES
ec40a1bbf8a4   test/redhat:7          "/sbin/init --system"    18 hours ago   Up 18 hours   22/tcp, 5432/tcp, 6432/tcp   crm17665d
cbd1ef55207c   test/redhat:7          "/sbin/init --system"    18 hours ago   Up 18 hours   22/tcp, 5432/tcp, 6432/tcp   crm17665c
b58c8054ad1c   test/redhat:7          "/sbin/init --system"    18 hours ago   Up 18 hours   22/tcp, 5432/tcp, 6432/tcp   crm17665b
3d78ef159e6f   test/redhat:7          "/sbin/init --system"    18 hours ago   Up 18 hours   22/tcp, 5432/tcp, 6432/tcp   crm17665a