Notes to Self

Alex Sokolsky's Notes on Computers and Programming

Docker Cheat Sheet



sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release -y
curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

In the following replace jammy with parent Ubuntu version name:

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] jammy stable" \
  | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null


sudo apt update
sudo apt-get install docker-ce docker-ce-cli

Verify the install:

> docker --version
Docker version 20.10.21, build baeda1f

> sudo docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:

For more examples and ideas, visit:

List images

docker image ls

List containers

List running:

docker container ls

List all containers, not only running, do not truncate output:

docker container ls -a --no-trunc

List IDs only:

docker container ls -q

Kill all containers

Force delete all containers:

docker container rm -f $(docker container ls -aq)

Inspect container

Inspecting container produces JSON:

sudo docker inspect _container_id_

Extract container environment and sort it.

sudo docker inspect _container_id_ | jq ".[0].Config.Env|sort[]"