Docker on Linux
The following assumes the previous installation of Ubuntu Server with no services installed except SSHD.
Install Docker
Installation instructions and a description of prerequisites are provided by [1].
First run the following to enter a shell with root privileges:
$ sudo bash
Next run apt update and upgrade. This is a sanity check to make sure our Linux OS is in a stable state so that if we encounter any problems it is most likely related to installing Docker.
# apt update # apt upgrade
Next we need to install Docker certificates to allow 'apt' to trust Docker packages. Note, as described in [1], we have replaced 'VERSION_CODENAME' with 'UBUNTU_CODENAME'.
# apt install ca-certificates curl # install -m 0755 -d /etc/apt/keyrings # curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc # chmod a+r /etc/apt/keyrings/docker.asc # 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") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Now we run apt update against to retrieve the Docker related package meta data:
# apt update
Now we can install the Docker related packages. If successful, we exit the root shell and call 'cd' to navigate back to our home directory.
# apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin # exit $ cd
Finally, verify the installation by running the 'hello-world' image, which should show output similar to below.
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world c1ec31eb5944: Pull complete Digest: sha256:d211f485f2dd1dee407a80973c8f129f00d54604d2c90732e8e320e5038a0348 Status: Downloaded newer image for hello-world:latest 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. (amd64) 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: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
Linux Post-installation Steps for Docker Engine
Practically speaking, if you want to easily use docker compose from another host, you will need to allow accounts to call 'docker' commands without using 'sudo'. To enable this, you will need to add the user to the 'docker' group using the following command.
$ sudo usermod -aG docker $USER
Warning: The above effectively gives that account root privileges, so this should only be done where security considerations have been analysed.
References
Install Docker Engine on Ubuntu
https://docs.docker.com/engine/install/ubuntu/
Linux Post-installation Steps for Docker Engine
https://docs.docker.com/engine/install/linux-postinstall/