install docker ubuntu
| |

How to install Docker on Ubuntu

In this post, we will learn how to install Docker on Ubuntu 22.04 LTS, 20.04 LTS, 18.04 LTS and 16.04 LTS. We have installed the Docker by using shell script in Ubuntu Operating System. We will use the recommended steps and commands to install docker on Ubuntu. We have clubbed all the recommended commands in our shell script for installing Docker.

Brief Introduction

Docker is a container platform software, by using Docker we can create containers.  Through Docker we can easily manage the containers and that is the reason it is quite popular. 

Requirements

Here are the requirements for installing Docker.
1. 64 Bit Operating System: Docker Engine is supported on x86_64 (or amd64), armhf, arm64, s390x (IBM Z), and ppc64le (IBM Power) architectures

2. Operating System (We recommend to use LTS):

  • Ubuntu Jammy 22.04 (LTS)
  • Ubuntu Focal 20.04 (LTS)
  • Ubuntu Bionic 18.04 (LTS)
  • Ubuntu Xenial 16.04 (LTS)

Note:
Remove the docker if it is already installed.

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get purge docker docker-engine docker.io containerd runc

Steps To Install Docker On Ubuntu

Create a file which will be the docker installation script.

vi install_docker_ubuntu.sh

Paste the following content in the file.

#!/bin/bash
# Description: Install docker on Ubuntu
# Blog: https://sharadchhetri.com
#
# Docker Supported Architecture: x86_64 (or amd64), armhf, arm64, s390x and ppc64le
#

_arch=$(dpkg --print-architecture)
sudo apt -y update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

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

sudo apt-get -y update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
sudo usermod -aG docker ${USER}

Give executable permission to the shell script.

sudo chmod +x install_docker_ubuntu.sh

Run the script, it will install the docker on Ubuntu.

sh install_docker_ubuntu.sh

Because we have added the current login user to group ‘docker’. To make it effective either logout or restart the system. Here we prefer to reboot the system.

sudo init 6

You can check the docker version by running the command docker --version

Output from our system

sharad@linuxworld:~$ docker --version
Docker version 19.03.11, build 42e35e61f3
sharad@linuxworld:~$ 

You can just pull any image for testing purpose also. For example, here we have pulled the ‘httpd’ image.

sharad@linuxworld:~$ docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
afb6ec6fdc1c: Pull complete 
5a6b409207a3: Pull complete 
41e5e22239e2: Pull complete 
9829f70a6a6b: Pull complete 
3cd774fea202: Pull complete 
Digest: sha256:590382d0aca313c3b0dbfd7c45afe92c76a729cceab3c8555edc03761b2b1b93
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest
sharad@linuxworld:~$ 

If all looks good, the docker is ready to use in your system.

git You can Git pull this script from our Github Repo called ‘scripts’

Similar Posts