Getting Started with Docker

This article is a quick tutorial on setting up Docker-ce on Ubuntu 20.


Introduction

“Our first obligation is to keep the foo counters turning.”Jargon File

This article is a quick tutorial on setting up Docker-ce on Ubuntu 20. It covers the steps necessary to download and install prerequisites, along with deploying and testing Docker.

There are many ways to deploy Docker.The process I’ve documented is the one I personally use, and it is how I’ve been deploying docker-ce in my own home lab environment.

Here are several links to Docker’s official documentation on deployment.


Installation Prerequisites

It’s always a good idea to update before doing installation commands. Doing so ensures we are using the most recent packages.

1
  apt-get update

Once we have completed the update, we can begin installing the prerequisites for downloading docker-ce.

1
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common

Before adding the Docker repository, we need to download the GPG key and add it to the trusted keys for APT sources. This allows us to trust the new repository.

1
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Once we have added the key, we can add the Docker repository to the APT sources.

1
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"


Installing Docker

Now that we have the Docker repository added, we can begin installing docker-ce, and its specific dependencies.

1
sudo apt install -y docker-ce

Once the installation is complete, we can check the docker service in systemctl and confirm that the service is active.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
sudo systemctl status docker


docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-02-08 20:50:00 UTC; 17h ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 15005 (dockerd)
      Tasks: 9
     Memory: 41.1M
     CGroup: /system.slice/docker.service
             └─15005 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock




Post-Configuration

At this point, we should have a fully deployed instance of Docker.The next step is to add the logged-in user to the docker security group. This allows docker specific commands to be run at a specific user level.

Note: please skip this step if you wish to keep Docker only accessible from a root-level account.

1
sudo usermod -aG docker ${USER}

Now that the user is added to the group, we can refresh the active user session with the updated groups.

1
su - ${USER}

Testing Docker

We should now run a quick test to ensure Docker is functioning correctly. We can test by instructing Docker to create a container with the hello-world image.

This test will look for a local copy of the image first. Docker will download a fresh copy of the image and create the container if none is found.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
docker run hello-world


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.

Once Docker has completed the run of hello-world, we can run a command to show all running and non-running containers.

1
2
3
4
5
docker ps -a

CONTAINER ID   IMAGE         COMMAND    CREATED              STATUS                          PORTS     NAMES
c598ccb17eba   hello-world   "/hello"   About a minute ago   Exited (0) About a minute ago             charming_hawking



Closing thoughts

Docker should now be fully installed and accessible! I will be adding additional Docker-related articles in the future, so stay tuned, and thank you for reading!



Back to Top