Table of contents

Installation

Prereqs and repository setup (Debian/Ubuntu)

sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg lsb-release

# Keyring directory and Docker GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL <https://download.docker.com/linux/ubuntu/gpg> | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Repository
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] [<https://download.docker.com/linux/ubuntu>](<https://download.docker.com/linux/ubuntu>) \
  $(lsb_release -cs) stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
# Include compose and buildx plugins
sudo apt-get install -y docker-ce docker-ce-cli [containerd.io](<http://containerd.io>) docker-buildx-plugin docker-compose-plugin

Post-install checks and optional non-root use

# Verify (works before non-root setup)
sudo docker run hello-world

# Optional: use Docker without sudo
sudo groupadd -f docker
sudo usermod -aG docker "$USER"
newgrp docker

# Verify again as current user (no sudo)
docker run hello-world

Gather some stats

Keep one working format string and remove duplicates.

docker stats --format "table .Container\[t.Name](<http://t.Name>)\t.CPUPerc\t.MemUsage\t.MemPerc"

Network management

Create, inspect, connect, disconnect

# Create with explicit subnet and gateway
docker network create --subnet 172.22.0.0/16 --gateway 172.22.0.1 my-net

# List
docker network ls

# Inspect
docker network inspect my-net

# Connect / disconnect a container
docker network connect my-net <container-id-or-name>
docker network disconnect my-net <container-id-or-name>