How to Install Docker on Ubuntu 20.0|22.04

[ad_1]

Docker is a open-source platform that uses OS-level virtualization to deliver software in packages called containers. Container is a unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.

Ubuntu 20.0|22.04 install, configure and uninstall docker; Through this tutorial, we will show you step by step how to install, configure and uninstall docker on Ubuntu 20.0|22.04 system.

How to Install and Uninstall Docker in Ubuntu 22.04

Steps to install, configure and uninstall docker on ubuntu 22.04 system using terminal or command line:

  • Step 1 – Update System Dependencies
  • Step 2 – Install Docker
  • Step 3 – Configure Sudo permissions for Docker

  • Step 4 – Using Docker Commands
    • Download Docker Images
    • Docker Commands
  • Step 5 – Uninstall Docker Ubuntu 20.0|22.04

Step 1 – Update System Dependencies

Use the following command to update the packages to the latest version available:

sudo apt update
sudo apt upgrade

Step 2 – Install Docker

Make sure we install the latest version of Docker from the official Docker repository. The official Ubuntu repository also has the Docker installation package, but it may not be the latest version.

Let’s play with some commands to install docker on ubuntu 22.04 system; is as follows:

Install some packages which allows you to use the packages over HTTPS.

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

Add the GPG key of Docker repository.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Now add the Docker repository of Ubuntu 22.04 (jammy) to the apt sources.

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

Update the packages index and setup your server to install Docker from official Docker repo.

sudo apt update
sudo apt-cache policy docker-ce

Then we will receive an output similar to this: as is follow:

Output
docker-ce:
  Installed: (none)
  Candidate: 5:20.10.14~3-0~ubuntu-jammy
  Version table:
     5:20.10.14~3-0~ubuntu-jammy 500
        500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
     5:20.10.13~3-0~ubuntu-jammy 500
        500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages

Execute the following command on command prompt to install Docker on ubuntu 22.04 system:

sudo apt install docker-ce

Once Docker is installed and the process is enabled to start on boot.

To check the status of Docker you can use the following command.

sudo systemctl status docker

The output will be like this.

Output
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-05-04 06:43:00 UTC; 2min 28s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 12995 (dockerd)
      Tasks: 8
     Memory: 38.6M
        CPU: 400ms
     CGroup: /system.slice/docker.service
             └─12995 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Step 3 – Configure Sudo permissions for Docker

If we want to run the docker command without sudo, so execute the following command with username on command prompt to the docker group:

sudo usermod -aG docker username

And restart SSH or open a new terminal to see the changes.

From now you use the docker command without sudo.

Step 4 – Using Docker Commands

Use the following command to view the system information about Docker; is as follows:

docker info

Download Docker Images

docker run hello-world

If the output you get is similar to the below then you can access and download images from Docker Hub.

Output
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

Execute the following command to see downloaded images:

docker images

Docker Commands

Once we have started using Docker, will have many active and inactive containers.

Use the following command to view all active containers:

docker ps

Use the following command to view all containers which are active and inactive:

docker ps -a

Use the following command to view the latest container:

docker ps -l

To start a docker container, use docker start command followed by the Container ID or Container Name:

docker start container-id/name

Likewise to stop a running container you can use the docker stop command followed by Container ID or Container Name:

docker stop container-id/name

If you no longer need the container you can remove the container with the docker rm followed by Container ID or Container Name:

docker rm container-id/name

To enter into interactive shell we can use the following command:

docker run -it container-id/name

Note that:- we can manually install commands inside the shell. For more details about docker commands use the docker run help command.

Step 5 – Uninstall Docker Ubuntu 20.0|22.04

Sometimes, you may need to completely remove or uninstall Docker in Ubuntu 20.0|22.04. You can do this by the following commands:

dpkg -l | grep -i docker

sudo apt-get purge -y docker-engine docker docker.io docker-ce docker-ce-cli

sudo apt-get autoremove -y --purge docker-engine docker docker.io docker-ce

sudo rm -rf /var/lib/docker /etc/docker

sudo rm /etc/apparmor.d/docker

sudo groupdel docker

sudo rm -rf /var/run/docker.sock

Conclusion

Through this tutorial, we have learned how to install, configure and uninstall Docker on Ubuntu 22.04.

[ad_2]

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00