Getting started with Docker - NidhiSingh0068/Docker-Content GitHub Wiki

To get started with Docker the Prerequisites are:

  1. [Ubuntu 20.04 Installed]
  2. A user account with sudo privileges
  3. Command-line/terminal
  4. Docker software repositories (optional)

Install Docker on Ubuntu 20.04

There are two options when for installing Docker on your Ubuntu system:

  1. Installing using the official Docker repository
  2. Installing using the default repositories

Note: It is recommended to install docker from official repository as it will let you install the latest version of docker, rather using default repositories might install older versions.

Here, I am installing Docker from Official Repository:

  1. Open the terminal and update the local repository:

sudo apt update

  1. Download dependencies: to allow ubuntu system to access the docker repositories.

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

The command:

  1. Gives the package manager permission to transfer files and data over https.(apt-transport-https)

  2. Allows the system to check security certificates.(ca-certificates)

  3. Installs curl, a a tool for transferring data.(curl)

  4. Adds scripts for managing software.(software-properties-common)

  5. Add dockers GPG key to ensure the authenticity of the software package.

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

Note: gpg is the tool used in secure apt to sign files and check their signatures. The above command might give a warning stating:

Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). curl: (6) Could not resolve host: download.docker.com gpg: no valid OpenPGP data found.

This is because it will no longer be used. Although adding keys directly to /etc/apt/trusted.gpg.d/ is suggested by apt-key deprecation message, as per [Debian Wiki]. (https://wiki.debian.org/DebianRepository/UseThirdParty) GPG keys for third party repositories should be added to /usr/share/keyrings and referenced with the signed-by option in the source.list.d entry. So, use

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/docker-ce-archive-keyring.gpg > /dev/null

Breakdown of each part

  1. curl downloads the key

  2. gpg --dearmor creates a binary .gpg because /usr/share/keyrings cannot take .asc keys

  3. sudo tee because we get permission denied if we try redirect the output of a sudo command

  4. dev/null we don't need to see the dearmored keyring on the console

  5. Installing docker Repository:

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

This command will install the latest version of docker for you OS version (ubuntu).

  1. Installing he latest docker: But first again update the repository agin.

sudo apt update

Now, install docker (Here installing docker community edition (ce) as it is free to use).

sudo apt-get install docker -ce

  1. Verify Docker Version.

docker --version

image

  1. Enable Docker Service. start docker service

sudo systemctl start docker

Enable Docker Service

sudo systemctl enable docker

Now, check status of service.

sudo systemctl status docker

image