Docker is a containerization technology that allows you to quickly build, test, and deploy applications as portable, self-sufficient containers that can run virtually anywhere. Docker has become the de facto standard for container deployment, and it is an essential tool for DevOps engineers and their continuous integration and delivery pipeline

In this post, we’ll cover how to install Docker on an Ubuntu 18.04 machine

First I log to my machine :

$ sudo apt update

Capture-d--cran-2020-01-29---22.40.25

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

Capture-d--cran-2020-01-29---22.33.23

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

Capture-d--cran-2020-01-29---22.34.28

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

Capture-d--cran-2020-01-29---22.41.42

Now that the Docker repository is enabled, you can install any Docker version you need

# to look docker versions
$ apt list -a docker-ce

Capture-d--cran-2020-01-29---22.42.32

$ sudo apt update

Capture-d--cran-2020-01-29---22.49.12

$ sudo apt install docker-ce

Capture-d--cran-2020-01-29---22.50.04

$ sudo systemctl status docker

Capture-d--cran-2020-01-29---22.50.41

# Executing docker command without sudo

$ sudo usermod -aG docker ${USER}

Docker Command-Line Interface

The Docker CLI command takes this form:

$ docker [option] [subcommand] [arguments]

Capture-d--cran-2020-01-29---22.53.01

Run the following command to take a look at the container image it pulled from Docker Hub:

This is the image pulled from the Docker Hub public registry. The Image ID is in SHA256 hash format—this field specifies the Docker image that's been provisioned. When the docker daemon can't find an image locally, it will by default search the public registry for the image.

# Search Docker Image
$ docker search ubuntu
# Download Docker Image
$ docker image pull ubuntu
# To list all downloaded images type:
$ docker image ls
# Start Docker Container
$ docker container run hello-world

Capture-d--cran-2020-01-29---22.57.32

This simple container returns Hello from Docker! to your screen. While the command is simple, notice in the output the number of steps it performed. The docker daemon searched for the hello-world image, didn't find the image locally, pulled the image from a public registry called Docker Hub, created a container from that image, and ran the container for you.

# The switch -it allows us to interact with the container via the command line. To start an interactive container type:
$ docker container run -it ubuntu /bin/bash

Capture-d--cran-2020-01-29---22.59.36

# Remove Docker Image
$ docker image ls
# Use images ls or Run the following command to take a look at the container image it pulled from Docker Hub:
$ docker images
$ docker image rm ubuntu
$ docker image ls

Capture-d--cran-2020-01-29---23.05.33

Capture-d--cran-2020-01-30---00.15.30

# List Docker Containers
# Look at the running containers by running the following command
$ docker container ls
# To view both active and inactive
$ docker container ls -a
# To delete one or more containers copy the container ID
# Exemple ID=f0b8e3deec3c for ubuntu container
$ docker container rm f0b8e3deec3c
$ docker container ls -a

Capture-d--cran-2020-01-29---23.04.43

You can uninstall Docker as any other package installed with apt

$ sudo apt purge docker-ce
$ sudo apt autoremove

Docker Compose

Docker Compose is a tool that allows you to define and manage multi-container Docker applications. It uses a YAML file to configure the application’s services, networks, and volumes.

The Docker Compose installation package is available in the official Ubuntu 18.04 repositories but it may not always be the latest version. The recommended approach is to install Docker Compose from the Docker’s GitHub repository.

To install Docker Compose on Ubuntu 18.04, follow these steps:

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Capture-d--cran-2020-01-29---23.22.37

$ sudo chmod +x /usr/local/bin/docker-compose

Capture-d--cran-2020-01-29---23.44.34

Verify the installation by running the following command which will display the Compose version:

$ docker-compose --version

Capture-d--cran-2020-01-29---23.45.36

You can uninstall Docker Compose  with  simply remove the binary by typing:

$ sudo rm /usr/local/bin/docker-compose
Learn more about Docker in the  official documentation

Enjoy! 😎