I’ve decided it’s finally time to learn containerization and am going to start with this blog. I’m running Ubuntu 24.04 and will be installing from the offical Docker repo since it’s the latest release. The Ubuntu repo often lags behind the official release.
Step 1 – Check if ca-certificates are installed. In order to download the packages from the Docker servers, curl will check the certificates to make sure it is legitimate:
dpkg -l ca-certificates
Step 2 – Check that there is a directory for the keyrings. It’s the designated place to store apt repository signing keys on Ubuntu:
ls -ld /etc/apt/keyrings
Step 3 – Next I downloaded the key and made sure it was readable by all users:
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
Step 4 – Next I added the Docker apt repository:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \
https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Check it with:
cat /etc/apt/sources.list.d/docker.list
Step 5 – Update and install:
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Check that it works:
sudo docker run hello-world
Step 6 – Give myself permission to run Docker without sudo:
sudo usermod -aG docker $USER
Some Basic Commands
Images
docker images # list images on your system
docker pull ubuntu # download an image
docker rmi ubuntu # remove an image
Containers
docker ps # list running containers
docker ps -a # list all containers (including stopped)
docker run hello-world # run a container from an image
docker run -it ubuntu bash # run interactively with a shell
docker stop <name/id> # stop a running container
docker rm <name/id> # remove a stopped container
Useful Run Flags
docker run -d ... # detached (background)
docker run -p 8080:80 ... # map host port 8080 to container port 80
docker run --name myapp ... # give it a name instead of a random one
Housekeeping
docker system df # see how much disk Docker is using
docker system prune # clean up stopped containers, unused images, etc.
Logs and Inspection
docker logs <name/id> # view container output
docker inspect <name/id> # detailed info about a container or image
Notes to Myself
- You cant delete an image if the container exists. And if the container is stopped, then
docker pswon’t show it, you need to dodocker ps -a