Docker

Docker Installation Guide for Beginners

In the first of Docker tutorial series, you'll learn to install the latest version of Docker Engine Community Edition on Ubuntu Linux.

Avimanyu
Abhishek Prakash
Avimanyu, Abhishek Prakash

Table of Contents

This is the first in our Docker tutorial series. In this article, you’ll learn how to install the latest Docker on Ubuntu and how to configure it.

By latest Docker, I mean the latest Docker Engine Community Edition (CE). Ubuntu also has Docker packages available in their repository, however, I would advise using the community edition.

For this tutorial, I created a new Ubuntu server on Linode. You may sign up for Linode and deploy your own Linux server in less than two minutes. They even provide $60 free credits to our readers.

Installing Docker on Ubuntu

Install Docker On Ubuntu

So, I presume you have an Ubuntu system installed. The first thing you should do is to update your system:

sudo apt update

If you already have any kind of Docker package installed, you should remove them as well to avoid conflict.

sudo apt remove docker docker-engine docker.io containerd runc

Now the following steps will get you an operational version of Docker CE up and running on your system.

Step 1: Enable installation via HTTPS

You need the following packages for using apt over https:

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

Some of the packages might already be installed on your system.

Step 2: Add the official Docker GPG key

Before you add the new repository from Docker, add its GPG key. Use the curl command to download the GPG key and then add it using apt-key command. You can combine both commands with pipe:

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

It’s a good idea to verify the key to avoid bad surprises:

sudo apt-key fingerprint 0EBFCD88

It’s output should be like this:

pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <[email protected]>
sub rsa4096 2017-02-22 [S]

Step 3: Add the Docker repository

Now that you have the repository key added, add the repository itself:

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

If you are using Ubuntu 16.04, you may have to update the repository as well:

sudo apt update

Step 4: Install Docker

Everything is set. Now you should install Docker and its related packages:

sudo apt install docker-ce docker-ce-cli containerd.io

Setting up Docker on Ubuntu

You have Docker installed but it’s not over just yet. You need to do some other basic setup and configuration in order to run it smoothly.

1. Run docker without sudo

One thing you should do is to add your username to docker group so that you don’t need to use sudo all the time.

The docker group may already exist. Use the groupadd command to create the group docker:

sudo groupadd docker

Add your username or other users to this group with usermod command. Change username with the actual user name.

sudo usermod -aG docker <username>

2. Verify docker installation by running a sample container

First, restart Ubuntu and then confirm that Docker is running fine by downloading and running the hello-world docker image:

docker run hello-world

It’s output should be like this:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest:
sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1a
c8d7
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working
correctly

To give you a better understanding, let me explain what happened here.

  • The Docker client contacted the Docker daemon.
  • The Docker daemon pulled the “hello-world” image from the Docker Hub.
  • The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
  • The Docker daemon streamed that output to the Docker client, which sent it to your terminal.

3. Run Docker at each boot

To make sure that Docker runs automatically on each boot, use this command:

sudo systemctl enable docker

That’s it. You have just learned to install Docker CE on Ubuntu Linux. Stay tuned for more Docker tutorials in this series.



Join the conversation.