[wpsm_toplist]
Docker is an open platform for developing, building and running containerised applications. It uses OS-level virtualization to deliver and run packages in a loosely isolated environment called containers.
As a developer, you first build the docker image for your application by writing a text document called Dockerfile and the application is then deployed as a container on the Docker host.
So to build the image and deploy the application as a container, you would need Docker on the server on which you are going to run the application. In this post we are going to look at all the steps required to install Docker on Ubuntu.
There are many options to install Docker on Ubuntu but we will look at below two options which are widely used.
sudo apt update
Update system apt package index
sudo apt install docker.io
Install Docker
sudo docker --version
verify the docker installation by checking the version and the output should show something similar to below.
rajesh@ubuntu:~$ sudo docker version
Client:
Version: 20.10.7
API version: 1.41
Go version: go1.13.8
Git commit: 20.10.7-0ubuntu5~20.04.2
Built: Mon Nov 1 00:34:17 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.8
Git commit: 20.10.7-0ubuntu5~20.04.2
Built: Fri Oct 22 00:45:53 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.5.5-0ubuntu3~20.04.2
GitCommit:
runc:
Version: 1.0.1-0ubuntu2~20.04.1
GitCommit:
docker-init:
Version: 0.19.0
GitCommit:
sudo apt update
Update system apt package index
sudo apt install ca-certificates curl gnupg lsb-release
Install above few packages which allows apt to communicate with repository over HTTPS
echo "deb [arch=$(dpkg --print-architecture) 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
Use above command to set the stable version of Docker that we are going to install.
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
Update the system apt package index again and run the Docker install command.
sudo docker --version
Verify the Docker installation by checking the version. You should be seeing output similar to below.
rajesh@ubuntu:~$ sudo docker version
Client: Docker Engine - Community
Version: 20.10.13
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 10 14:07:51 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.13
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 906f57f
Built: Thu Mar 10 14:05:44 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.5.10
GitCommit: 2a1d4dbdb2a1030dc5b01e96fb110a9d9f150ecc
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0
We can only run the docker commands from root or sudo or by the users who are part of docker group.
sudo usermod -aG docker <username>
Add the user to the docker group if you want to avoid using root or sudo. You will need to restart the machine for this to take effect.
docker run hello-world
Run the above command to create your first hello-world container. This will show “Hello from Docker!” along with other information.
Here are the steps Docker took to display this message:
Conclusion
In this tutorial, you have learned how to install Docker on Ubuntu and created a sample docker container. It is time for you to go in depth and try all the features which Docker offers.