Marx J. Moura

05 September 2019

How to install Docker on Ubuntu


Docker container images allow us to optimize the process of creating, deploying, and running applications. Let's start by installing Docker to get these benefits and learn more about how it works.

Docker is an open-source and well documented platform that allow us to run images inside isolated containers. These images can be entire applications that can be shared as packages through Docker Hub and published across multiple environments using specific settings.

Docker works based on Linux Containers (LXC) that allow us to run multiple isolated Linux systems (containers) using a single host and a single kernel, unlike a VM (Virtual Machine).

Each container acts like a virtual machine but, without the hardware simulation overhead (performed by virtualizer or emulator). By default, the containers use the host resources (CPU, RAM, etc) without restriction. However, Docker allow us to limit the container by setting resource constraints.

To start getting these benefits, let's install it by following these two steps that you can also find in the Docker documentation:

  1. Uninstall any old versions of Docker
  2. Install Docker

Uninstall any old versions of Docker

It's recommended to uninstall older versions of Docker before proceeding:

sudo apt-get remove docker docker-engine containerd runc

Install Docker

To install Docker CE (Community Edition) for the first time on Ubuntu we need to register the Docker repository.

Before install, let's update the apt indexes:

sudo apt-get update

Next, let's install the packages needed for atp to use repositories over HTTPS:

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

Now, let's add the official Docker GPG key:

curl -fsSL | sudo apt-key add -

Then, add the stable release repository of Docker:

sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"

Update apt indexes one more time:

sudo apt-get update

Finally, install Docker by running the following command:

sudo apt-get install docker-ce docker-ce-cli

You may have notice that we installed three packages, let's briefly understand each one:

To confirm that Docker has been successfully installed:

sudo docker run hello-world

This command downloads a test image and runs it in a container that prints a message and exits. The displayed message should start with "Hello from Docker!".

Once installed and running correctly we can manage the Docker images. But this we will discuss in an upcoming post.


I'm Marx J. Moura. In this blog I write about microservice architecture and web application development.