Installing Docker.

Or: Containing my Code so it Runs Anywhere.


11 min read

Installing Docker.

Update: Tuesday 20th February 2024.


This post explains how to install Docker, a tool that makes it easy to develop, ship, and run apps. Docker puts an app's code, infrastructure, libraries, and dependencies into one small package that runs on any computer. To install Docker, I update my system, install any requirements, add Docker's official GPG key, install the Docker repository, and check the installation. This post also shows how to uninstall Docker. The main advantages of using Docker include:

  • An ability to run my apps on any system,

  • Isolating processes from other containers and the host,

  • Quick assembly and deployment, and

  • Easily making containers for my apps.


An Introduction.

Docker is a utility that helps me package my applications so they can run on any computer system.

The purpose of this post is to present a process for installing, and using, Docker.

The Big Picture.

Docker is a container system. The main advantages of using Docker include:

  • The isolation of running processes,

  • The ease of creating new containers,

  • Fast deployments, and

  • Fast migrations.


  • A Linux-based distro (I use Ubuntu).

What is Docker?

Docker is a free tool that helps me develop, ship, and run my applications in containers. Containers are lightweight bundles that package my application source code, infrastructure, libraries, and dependencies into one file that can run on any PC.

Installing Docker.

  • I update my (base) system:
sudo apt clean && \
sudo apt update && \
sudo apt dist-upgrade -y && \
sudo apt --fix-broken install && \
sudo apt autoclean && \
sudo apt autoremove -y
  • I install the following requirements:
sudo apt install -y ca-certificates curl gnupg lsb-release
  • I make a keyrings directory:
mkdir -m 0755 -p /etc/apt/keyrings
  • I add Docker’s official GPG key:
curl -fsSL | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  • I change the mode of the docker.gpg file:
sudo chmod a+r /etc/apt/keyrings/docker.gpg
  • I install the Docker repository:
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
  • I update my (base) system:
sudo apt clean && \
sudo apt update && \
sudo apt dist-upgrade -y && \
sudo apt --fix-broken install && \
sudo apt autoclean && \
sudo apt autoremove -y
  • I install the Docker Community Edition engine, the Docker CLI, the container daemon, and the Buildx and Compose plugins:
sudo apt install -y docker-ce docker-ce-cli docker-buildx-plugin docker-compose-plugin

Checking Docker.

  • I check if Docker is active:
systemctl is-active docker
  • I check the status of Docker:
service docker status
  • I check the Docker version:
sudo docker version
  • I list the information for Docker:
sudo docker info

Docker Setup.

  • I create the Docker group, if required:
sudo groupadd docker
  • I add my user account to the Docker group:
sudo usermod -aG docker ${USER}
  • I verify the installation:
sudo docker run hello-world
  • I reboot the homelab system to load the Docker settings into memory (or I can reboot the system after installing Distrobox.)

Uninstalling Docker.

  • This command uninstalls Docker:
for pkg in docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt remove $pkg; done

Docker Commands.

The commands I commonly use are highlighted in yellow.

Management -al

docker dockerdLaunch the Docker daemon
docker infoDisplay system-wide information
docker inspectReturn low-level information on a container or image
docker versionShow the Docker version information

Image Commands.

docker buildBuild an image from a Dockerfile
docker commitCreate a new image from a container’s changes
docker historyShow the history of an image
docker image rm [ID] -fRemove image by ID
docker imagesList images
docker importImport the contents from a tarball to create a filesystem image
docker loadLoad an image from a tar archive or STDIN
docker rmiRemove one or more images
docker saveSave images to a tar archive
docker tagTag an image into a repository

Container Commands.

docker attachAttach to a running container
docker container prune -fRemove all stopped containers
docker cpCopy files/folders from a container to a HOSTDIR or to STDOUT
docker createCreate a new container
docker diffInspect changes on a container’s filesystem
docker eventsGet real time events from the server
docker execRun a command in a running container
docker exportExport a container’s filesystem as a tar archive
docker killKill a running container
docker logsFetch the logs of a container
docker pausePause all processes within a container
docker portList port mappings or a specific mapping for the container
docker psList running containers
docker ps -f "status=exited"List stopped containers
docker renameRename a container
docker restartRestart a running container
docker rmRemove one or more containers
docker runRun a command in a new container
docker startStart one or more stopped containers
docker statsDisplay a live stream of container(s) resource usage statistics
docker stopStop a running container
docker topDisplay the running processes of a container
docker unpauseUnpause all processes within a container
docker updateUpdate configuration of one or more containers
docker waitBlock until a container stops, then print its exit code

Shared Data Volume Commands.

docker volumes createCreates a new volume where containers can consume and store data
docker volumes inspectDisplay information about a volume
docker volumes lsLists all the volumes Docker knows about
docker volumes rmRemove one or more volumes

Hub and Registry Commands.

docker loginRegister or log in to a Docker registry
docker logoutLog out from a Docker registry
docker pullPull an image or a repository from a Docker registry
docker pushPush an image or a repository to a Docker registry
docker searchSearch the Docker Hub for images

Network and Connectivity Commands.

docker network connectConnect a container to a network
docker network createCreate a new network
docker network disconnectDisconnect a container from a network
docker network inspectDisplay information about a network
docker network lsLists all the networks the Engine daemon knows about
docker network rmRemoves one or more networks

Swarm Commands.

docker swarm initInitialize a swarm
docker swarm joinJoin a swarm as a manager node or worker node
docker swarm leaveRemove the current node from the swarm
docker swarm updateUpdate attributes of a swarm
docker swarm join-tokenDisplay or rotate join tokens

Swarm Service Commands.

docker service createCreate a new service
docker service inspectInspect a service
docker service lsList services in the swarm
docker service rmRemove a service from the swarm
docker service scaleSet the number of replicas for the desired state of the service
docker service psList the tasks of a service
docker service updateUpdate the attributes of a service

Swarm Node Commands.

docker node promotePromote a node that is pending a promotion to manager
docker node demoteDemotes an existing manager so that it is no longer a manager
docker node inspectInspect a node in the swarm
docker node updateUpdate attributes for a node
docker node psList tasks running on a node
docker node lsList nodes in the swarm
docker node rmRemove one or more nodes from the swarm

Compose Commands.

docker compose attachAttach local standard input, output, and error streams to a service's running container
docker compose buildBuild or rebuild services
docker compose configParse, resolve and render compose file in canonical format
docker compose cpCopy files/folders between a service container and the local filesystem
docker compose createCreates containers for a service
docker compose downStop and remove containers, networks
docker compose eventsReceive real time events from containers
docker compose execExecute a command in a running container
docker compose imagesList images used by the created containers
docker compose killForce stop service containers
docker compose logsView output from containers
docker compose lsList running compose projects
docker compose pausePause services
docker compose portPrint the public port for a port binding
docker compose psList containers
docker compose pullPull service images
docker compose pushPush service images
docker compose restartRestart service containers
docker compose rmRemove stopped service containers
docker compose runRun a one-off command on a service
docker compose scaleScale services
docker compose startStart services
docker compose statsDisplay a live stream of container(s) resource usage statistics
docker compose stopStop services
docker compose topDisplay the running processes
docker compose unpauseUnpause services
docker compose upCreate and start containers
docker compose versionShow the Docker Compose version information
docker compose waitBlock until the first service container stops
docker compose watchWatch build context for service and rebuild/refresh containers when files are updated

The Results.

Docker is an invaluable tool that allows me to package my applications into containers, ensuring that they can run on any system. This simplifies the process of developing, shipping, and running my applications, and also enhances the efficiency of deployments and migrations. After going through the installation process, I should now have Docker installed on my Linux-based system, and be able to leverage its capabilities to improve my development workflow. Remember, the power of Docker lies in its ability to isolate running processes and easily create new containers, improving the way I deploy my applications.

In Conclusion.

How do I package my applications so they can run on ANY computer?

This was Docker, a container system that isolated any running processes, easily created new containers, supported fast app deployments, and allowed quick and easy migrations. It was like having my own, personal mini-shipyard for "shipping" applications to... anywhere.

How did it work?

Docker packaged the source code for my app, its infrastructure, any required libraries, and all the needed dependencies into one lightweight bundle. This bundle, or 'container', could then run on any PC. It was like having my entire tech stack in a portable suitcase!

This guide walked me through installing Docker.

First, I needed a Linux-based distro. I use Ubuntu. Then followed these steps:

  1. I updated my system.

  2. I installed the necessary requirements.

  3. I made a 'keyrings' directory.

  4. I added Docker’s official GPG key.

  5. I changed the mode of the 'docker.gpg' file.

  6. I installed the Docker repository.

  7. I updated the repo list.

  8. I installed Docker and its requirements.

  9. I checked if Docker was active.

  10. I verified the installation.

  11. I rebooted the system to load the Docker settings into memory.

Voila! I installed Docker.

But what if I wanted to uninstall Docker? Just one command does the trick. Easy-peasy, right?

Docker is an invaluable tool that simplifies the process of developing, shipping, and running applications. It's a game-changer in the world of deployments and migrations.

So, who's ready to give Docker a try? Or if you're already using it, share your experience. How has Docker improved your workflow?

Until next time: Be safe, be kind, be awesome.