Install Docker on Ubuntu
Tags: docker, beginners, tutorial
Published: 2022-05-25 11:01:00


## Install Docker on Ubuntu
## Table of Content
  - [Introduction](#introduction)
  - [Steps to Install Docker Explained](#steps-to-install-docker-explained)
  - [Installation as Shell Script](#installation-as-shell-script)
  - [Docker run output of Hello World Container](#docker-run-output-of-hello-world)
  - [Bibliography](#bibliography)

## Introduction
- We will see how to install docker on Ubuntu, in this article
- Purpose of this tutorial is to provide the comprehensive steps focusing on the installation and verification of Docker on Ubuntu
- This blog is a repost of my same blog published in dev.to

## Steps to Install Docker Explained
- Setup the Repository
- Update the apt package index and install packages to allow apt to use a repository over HTTPS:
```
sudo apt-get update
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get install  apt-transport-https ca-certificates curl     gnupg-agent software-properties-common
```
- Add Docker’s official GPG key:
```
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
```
```
# Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.

sudo apt-key fingerprint 0EBFCD88
```
- Set up the stable repository:
```
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
```
- Install Docker Engine
```
# Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
```
- Verify that Docker Engine Installation
```
# Verify Docker Is installed correctly by running the hello-world image.
sudo docker run hello-world
```

## Installation as Shell Script
```
# SET UP THE REPOSITORY
# Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get update -y 
sudo apt-get remove -y docker docker-engine docker.io containerd runc
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common

# Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88, 
# by searching for the last 8 characters of the fingerprint.
sudo apt-key fingerprint 0EBFCD88

# Use the following command to set up the stable repository. 
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

# Update the apt package index, and install the latest version of Docker Engine and containerd, 
# or go to the next step to install a specific version:
sudo apt-get update -y
sudo apt-get install -y docker-ce docker-ce-cli containerd.io

# Verify that Docker Engine is installed correctly by running the hello-world image.
sudo docker run hello-world
```

- Script source available in [My Chefgs GitHub](https://github.com/chefgs/sh_workouts/blob/main/install_docker.sh)

## Docker run output of Hello World
```
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
```

### Bibliography
This article is inspired from the [Docker installation documentation](https://docs.docker.com/engine/install/ubuntu/#installation-methods)
Issue: socket permission denied. [Resolution](https://stackoverflow.com/questions/47854463/docker-got-permission-denied-while-trying-to-connect-to-the-docker-daemon-socke)