Getting started with Docker - NidhiSingh0068/Docker-Content GitHub Wiki
To get started with Docker the Prerequisites are:
- [Ubuntu 20.04 Installed]
- A user account with sudo privileges
- Command-line/terminal
- Docker software repositories (optional)
Install Docker on Ubuntu 20.04
There are two options when for installing Docker on your Ubuntu system:
- Installing using the official Docker repository
- 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:
- Open the terminal and update the local repository:
sudo apt update
- 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:
-
Gives the package manager permission to transfer files and data over https.(apt-transport-https)
-
Allows the system to check security certificates.(ca-certificates)
-
Installs curl, a a tool for transferring data.(curl)
-
Adds scripts for managing software.(software-properties-common)
-
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
-
curl downloads the key
-
gpg --dearmor creates a binary .gpg because /usr/share/keyrings cannot take .asc keys
-
sudo tee because we get permission denied if we try redirect the output of a sudo command
-
dev/null we don't need to see the dearmored keyring on the console
-
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).
- 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
- Verify Docker Version.
docker --version
- 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