Overview

This tutorial provides instructions for installing Docker on Ubuntu. While the steps outlined here may work for other versions of Ubuntu (and some non-Ubuntu Linux distributions), these instructions were tested against Ubuntu 20.04 LTS.

Outcomes

  • A working docker installation

Prerequisites

Before starting this tutorial, ensure that ...

Background

Docker is both a software company and a popular software implementation of containerization. We'll be using it throughout this course to run examples and assignments.

Installation

The Docker engine can be installed on MacOS, Linux, and even Windows* (with some caveats). This tutorial provides instructions for installing Docker on Ubuntu 20.04 LTS using the command line.

MacOS

If you would like to install on MacOS (Docker Desktop), follow the official installation instructions:

Note, however, that there are numerous things you will need to configure.

At the time of this writing, I do not recommend installing Docker Desktop on Windows. I recommend that Windows users instead install docker in a Linux virtual machine.

We'll use the linux CLI to install Docker on Ubuntu. From your terminal, ...

Step 1: Update your system

Before install docker, let's update our package index:

sudo apt-get -y update

Step 3: Install docker and docker-compose

We'll install the community edition of Docker (the docker-ce package) along with a tool for orchestrating several containerized services:

sudo apt install -y docker.io
sudo apt install -y docker-compose

Step 4 (Optional): Configure Docker to run without sudo

Running docker requires adminstrative priveleges. Theses priveleges are invoked by using the sudo commmand. To avoid needing to type this

#sudo groupadd docker
sudo usermod -aG docker $USER
# avoid the need to restart to apply changes
newgrp docker

You can learn more about this step here.

Testing your installation

To test our installation, we'll pull (download) the hello-world image from DockerHub and launch a container using that image:

docker run hello-world:latest

👀 If you get a permission error, run the command with sudo (i.e., sudo docker run hello-world:latest).

By convention, the :latest tag should reference the most recent version of the image.

You should see output like the following:

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/

Congrats! You're ready to run containerized apps!

Next steps

For an introduction to using Docker, see this tutorial.

Creative Commons License