Post

Docker Installation

In this walkthrough, i am going to show you how you can install docker on Ubuntu 20.04 in just 10 steps. However, minimal and cloud native OS are the preferred choice for a docker host since they are designed and configured to run containers and given their small footprint, they consume relatively fewer resources that their counterparts. Some of these Operating systems Include:

Feel free to explore the above and compare the difference. Let me explain about the docker architecture briefly before we go further.

Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers. The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate using a REST API, over UNIX sockets or a network interface. Another Docker client is Docker Compose, that lets you work with applications consisting of a set of containers. Source: Docker Documentation

image

If you had previously installed docker on your system and you happened to encounter some problems for some reason, you can follow along but first you will need to run the following command in order to uninstall older versions, for example docker, docker.io, or docker-engine

1
sudo apt-get remove docker docker-engine docker.io containerd runc

The contents of /var/lib/docker/, including images, containers, volumes, and networks, are preserved. If you do not need to save your existing data, and want to start with a clean installation, simple run the following commands

1
2
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

With that done, lets get started.

  1. We’ll start by updating and upgrading our system using the following command
1
sudo apt-get update && sudo apt-get upgrade -y
  1. We also need to install a few prerequisite packages which let apt use packages over HTTPS
1
2
3
4
5
6
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
  1. Add Docker’s official GPG key:
1
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  1. Add the Docker repository to APT sources:
1
2
3
 echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  1. Update the package database with the Docker packages from the newly added repo:
1
sudo apt-get update
  1. To make sure you are about to install from the Docker repo instead of the default Ubuntu repo:
1
apt-cache policy docker-ce

You’ll see output like this, although the version number for Docker may be different:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
docker-ce:
  Installed: (none)
  Candidate: 5:20.10.7~3-0~ubuntu-focal
  Version table:
     5:20.10.7~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.6~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.5~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.4~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.3~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.2~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.1~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:20.10.0~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.15~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.14~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.13~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.12~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.11~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.10~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     5:19.03.9~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
  1. Update the apt package index, and install the latest version of Docker Engine and containerd
1
2
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
  1. Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running:
1
sudo systemctl status docker

The output should be similar to the following, showing that the service is active and running:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-07-30 13:52:36 EAT; 3min 37s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 6836 (dockerd)
      Tasks: 8
     Memory: 53.4M
     CGroup: /system.slice/docker.service
             └─6836 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Ado 30 13:52:34 docker dockerd[6836]: time="2021-07-30T13:52:34.834129261+03:00" level=warning msg="Your kernel does not support CPU realtime >
Ado 30 13:52:34 docker dockerd[6836]: time="2021-07-30T13:52:34.835495233+03:00" level=warning msg="Your kernel does not support cgroup blkio >
Ado 30 13:52:34 docker dockerd[6836]: time="2021-07-30T13:52:34.835857823+03:00" level=warning msg="Your kernel does not support cgroup blkio >
Ado 30 13:52:34 docker dockerd[6836]: time="2021-07-30T13:52:34.836753497+03:00" level=info msg="Loading containers: start."
Ado 30 13:52:35 docker dockerd[6836]: time="2021-07-30T13:52:35.486328397+03:00" level=info msg="Default bridge (docker0) is assigned with an >
Ado 30 13:52:35 docker dockerd[6836]: time="2021-07-30T13:52:35.989845144+03:00" level=info msg="Loading containers: done."
Ado 30 13:52:36 docker dockerd[6836]: time="2021-07-30T13:52:36.855617392+03:00" level=info msg="Docker daemon" commit=b0f5bc3 graphdriver(s)=>
Ado 30 13:52:36 docker dockerd[6836]: time="2021-07-30T13:52:36.856528926+03:00" level=info msg="Daemon has completed initialization"
Ado 30 13:52:36 docker systemd[1]: Started Docker Application Container Engine.
Ado 30 13:52:37 docker dockerd[6836]: time="2021-07-30T13:52:37.201020910+03:00" level=info msg="API listen on /run/docker.sock"
  1. We can check the docker version by simply running the following command
1
2
3
docker@docker:~/Desktop$ docker --version
Docker version 20.10.7, build f0df350
docker@docker:~/Desktop$
  1. To verify that Docker Engine is installed correctly by running the hello-world image.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
docker@docker:~/Desktop$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
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/
docker@docker:~/Desktop/

That was easy and smooth, right? So “Now we have docker installed, what next?” In the next article, I’m going to be taking through some of the basic docker commands that will get you started. Until then, thanks for reading and following through. If you have any question about the same, feel free to ping me on twitter @oste_ke

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.