How to install Docker on Ubuntu 21.04 / 20.04
Summary
This tutorial will explain how you'll need to install Docker on Ubuntu 21.04 Docker is an open source containerization platform. It is an application build and deployment tool. Docker is based on the idea of packaging your code with all its dependencies into a deployable unit called a container.
Updating Package Manager
Update your package manager by using the following command.
sudo apt-get update -y
Installing Docker
You can install Docker by using the following command.
sudo apt-get install docker.io -y
Now we need to enable the service so it will start at startup. This can be done with the following command.
systemctl enable --now docker
To check if the service is running you can use the following command.
systemctl status docker
Output should look something like this.
â docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-04-15 09:38:44 CEST; 51min ago
TriggeredBy: â docker.socket
Docs: https://docs.docker.com
Main PID: 2969 (dockerd)
Tasks: 11
Memory: 48.2M
CGroup: /system.slice/docker.service
ââ2969 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
To check the Docker version you can use the following command.
docker --version
You can test docker by using the hello-world container. To run the container you can use this command.
docker run hello-world
The output should look something like this.
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519
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/