Unless otherwise noted, commands run on Ubuntu 22.


# Add the current user to the docker group so docker can be run without sudo.
sudo usermod -aG docker ${USER}
su - ${USER}


# Get installed version.
docker -v

# Verify Docker is setup / run the Hello World image.
sudo docker run hello-world

# Check whether Docker is running.
sudo systemctl status docker

# Search Docker Hub for all images matching a search term (<term>).
docker search <term>

# Show all downloaded images.
docker images

# Remove an image.
docker rmi <image-id>


# List running containers.
docker ps
# List all containers.
docker ps -a

# Start a container with <container-id> or <container-name>.
docker start <container-id>
docker start <container-name>

# Stop a container.
docker stop <container>

# Restart a container.
docker restart <container>

# Remove/delete a container.
docker rm <container>

# View container's logs.
docker logs <container>

Working with Running Containers

docker cp path/to/file <container>:./destination/path/

# Run bash on the container, if installed.
docker exec -it <container> bash


# Show disk usage.
docker system df
docker system df --verbose

# Show active container stats.
docker stats

# View and prune images.
docker image ls --filter dangling=true
docker image prune


# Stop based upon docker-compose.yml in directory.
docker compose stop

# Start services based upon docker-compose.yml.
docker compose up -d

Install on Ubuntu

On Ubuntu, from

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli docker-buildx-plugin docker-compose-plugin

# Test.
sudo docker run hello-world