Want to install Docker on Ubuntu?
If yes, this is the article for you. In this article, we are going to show you how to install the latest version of Docker on Ubuntu in the simplest possible form.
Docker is one of the most used container technology. Some of you even might not know what are other alternatives to Docker. Yes, there are! LXD and rkt are a few of them.
Docker is also one of the stacks of DevOps technologies and is currently a very good technology to know and learn If you want to grow in your career.
Prerequisites to Install Docker on Ubuntu 20.04
- Knowledge of Linux Command Line
- Ubuntu 20.04 Machine
- Internet Access
Note: We are using Ubuntu EC2 instance from AWS.
Steps to Install Docker on Ubuntu 20.04
1. SSH to your Ubuntu server and update the package registry.
ssh -i path-to-key
sudo apt-get update -y
You will see the below output:
ubuntu@ip-172-31-2-197:~$ sudo apt-get update
Hit:1 http://xyx.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://xyx.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://xyx.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
...................................
...................................
Get:35 http://security.ubuntu.com/ubuntu focal-security/restricted Translation-en [58.3 kB]
Get:36 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 c-n-f Metadata [508 B]
Get:37 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [638 kB]
Get:38 http://security.ubuntu.com/ubuntu focal-security/universe Translation-en [101 kB]
Get:39 http://security.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [12.4 kB]
Get:40 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [21.9 kB]
Get:41 http://security.ubuntu.com/ubuntu focal-security/multiverse Translation-en [4948 B]
Get:42 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 c-n-f Metadata [540 B]
Fetched 20.0 MB in 3s (6536 kB/s)
Reading package lists... Done
2. Now install apt-transport-https, ca-certificates, curl, gnupg, and lsb-release packages to allow the package manager to use a repository over HTTPS and add Docker’s official GPG key.
sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg \ lsb-release curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
You will see something like below:
ubuntu@ip-172-31-4-123:~$ sudo apt-get install \
> apt-transport-https \
> ca-certificates \
> curl \
> gnupg \
> lsb-release
Reading package lists... Done
Building dependency tree
Reading state information... Done
lsb-release is already the newest version (11.1.0ubuntu2).
lsb-release set to manually installed.
ca-certificates is already the newest version (20210119~20.04.1).
ca-certificates set to manually installed.
gnupg is already the newest version (2.2.19-3ubuntu2.1).
gnupg set to manually installed.
The following additional packages will be installed:
libcurl4
......................................
......................................
Fetched 400 kB in 0s (20.0 MB/s)
Setting up curl (7.68.0-1ubuntu2.6) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
ubuntu@ip-172-31-4-123:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
ubuntu@ip-172-31-4-123:~$
3. Use the below command to set up the required repository.
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
4. Once the above step is done, now it’s time to install Docker. The “docker-ce” is the community edition of Docker.
sudo apt-get update -y
sudo apt-get install docker-ce docker-ce-cli containerd.io
You should see an output similar to the below one. Output is truncated.
ubuntu@ip-172-31-4-123:~$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
Suggested packages:
aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed:
containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
0 upgraded, 7 newly installed, 0 to remove and 108 not upgraded.
Need to get 96.7 MB of archives.
.........................................
.........................................
Setting up docker-ce-rootless-extras (5:20.10.8~3-0~ubuntu-focal) ...
Setting up docker-ce (5:20.10.8~3-0~ubuntu-focal) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3.6) ...
5. Once the above step is completed, you can verify the Docker version with “sudo docker version” and can run a hello-worldcontainer.
ubuntu@ip-172-31-4-123:~$ sudo docker version
Client: Docker Engine - Community
Version: 20.10.8
API version: 1.41
Go version: go1.16.6
Git commit: 3967b7d
Built: Fri Jul 30 19:54:27 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.8
API version: 1.41 (minimum version 1.12)
Go version: go1.16.6
Git commit: 75249d8
Built: Fri Jul 30 19:52:33 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.9
GitCommit: e25210fe30a0a703442421b0f60afac609f950a3
runc:
Version: 1.0.1
GitCommit: v1.0.1-0-g4144b63
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Running hello-world container with “sudo docker run hello-world”
ubuntu@ip-172-31-4-123:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:7d91b69e04a9029b99f3585aaaccae2baa80bcf318f4a5d2165a9898cd2dc0a1
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/
ubuntu@ip-172-31-4-123:~$
Congrats you have installed Docker Ubuntu. Now play with it, learn Docker or build awesome containerized applications.
These were the simple steps to install Docker on Ubuntu 20.04. If you have any questions or feedback, please let us know through your comments.