Categories: ShellUbuntu

How to Install and Use Docker on Ubuntu 20.04

Docker is a compact virtualization that runs on top of the operating system, allowing users to design, run, and deploy applications encased in small containers. It is a collection of platform-as-a-service (PaaS) tools for launching and managing containers. Docker containers are used by developers to develop and deploy apps because they are isolated and lightweight.

Docker has transformed the software engineering business, changing not just how we deliver and deploy applications but also how engineers build-up application development environments on their workstations.

Linux containers are robust, scalable, and secure. A Docker container's processes are always insulated from the host system, avoiding manipulation from the outside.

In this tutorial, I will show you how to install, use, and remove Docker on an Ubuntu Linux system.

Prerequisites

  • Ubuntu or any other Debian-based distribution
  • Terminal access
  • Sudo or root privileges
  • Internet access

Note: Although the commands used in this tutorial are specifically for the Ubuntu system, all the methods are also valid for any other Linux-based system.

Install Docker From the System Repository

Docker is included and comes by default with the Ubuntu system. Install the Docker through the following steps.

Update Your System

Always update your system repositories before any installation.

sudo apt update

Remove Any Previous Docker Installations

Remove any older version of Docker using the following command for a fresh installation.

sudo apt-get remove docker docker-engine docker.io

Install Docker from the Local Repository

Next, install Docker by running the following apt command.

sudo apt install docker.io

Check the Docker Version

Check the Docker version with the following command.

docker --version

You can see the version is not the latest available version, you have to install it from its official repository to get the latest available version.

Install Docker From the Docker Official Repository

Update Your System

Update the system repositories by running the following command.

sudo apt update

Install Dependencies

Install the dependency packages to access the Docker repository over HTTPS.

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

Add the GPG Key

To add the GPG key of the Docker repository, run the following command.

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

Install the Docker Repository

Next, to install the Docker repository, run.

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

And update your system again.

sudo apt update

Install Docker

Finally, install Docker using the following command.

sudo apt-get install docker-ce

Check the Docker Version

To verify that you have the latest available version of Docker on your system, run the following command.

docker --version

Start and Enable the Docker Service

You can start and enable Docker services using the following commands.

sudo systemctl start docker
sudo systemctl enable docker

Verify that the Docker service has started by its status.

sudo systemctl status docker

You can see that the Docker service is running.

Stop and Disable the Docker Service

Similarly, you can run the systemctl commands to stop and disable the Docker services.

sudo systemctl disable docker

Disabling the services will make sure that Docker services will not automatically start at system boot.

sudo systemctl stop docker

Uninstall Docker On Ubuntu

You can remove Docker from your system with the following commands

sudo apt-get remove docker docker-engine docker.io

sudo apt-get remove docker.ce

Use Docker in Ubuntu

Run a Container in Docker

To run a container in Docker, use the following command.

sudo docker run <container>

You can see that sudo or root privilege is required to run Docker. To opt-out of this, you have to add the docker group to sudo and then the user in the docker group. To do that, run the following commands.

sudo groupadd docker
sudo usermod -aG docker <user>

Run the following command for changes to take effect.

su - <user>

And verify the changes.

id -nG

You can see the docker group in the output. Now you can run Docker commands without sudo.

docker run hello-world

Search for Images in Docker

To search for a specific Docker image, you can search with the image name in Docker.

docker search <image-name>

List All Docker Images in Docker

Or you can list all the images with the following command.

docker images

List All Container in Docker

Similarly, you can list all the containers in Docker with the following command.

docker container ps -a

Conclusion

Docker is an extremely flexible technology with various applications in software development. Docker will ease the way you distribute software in diverse settings and is excellent for testing and prototyping applications, whether you are a software developer or work in DevOps.

This tutorial discussed how you can install and uninstall dockers on your Ubuntu system. It also briefly teaches some basic use of Docker.

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

Recent Posts

How to Install Magento 2 on AlmaLinux

Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…

1 year ago

How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04

ISPConfig is an open-source control panel that allows users to manage multiple servers from a…

1 year ago

How to Test your Email Server (SMTP) Using the Telnet Command

As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…

1 year ago

Managing Network Interfaces and Settings on Ubuntu 24.04 with nmcli

Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…

2 years ago

Using Restic Backup on Ubuntu 24.04

Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…

2 years ago

Installing phpMyAdmin on Rocky Linux 9 and Securing it with Let’s Encrypt SSL

phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…

2 years ago