Docker is one of the most popular tools used for containerization. This article contains step by step instructions for installing and configuring docker in Ubuntu. These instructions will work on Ubuntu versions 16.04, 18.04 and 18.10. If you have a different Ubuntu version, you may experience problems.

This article is a short and simple version of the official guide. If you need a more in-depth instructions or if you experience any problem during installation, take a look at the following links

Install Dependencies and Configure Repositories

Remove older versions of docker and dependencies if any of them are installed.

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

Now we need to install some packages for configuring apt to use HTTPS and some other packages for to be used in next steps.

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

Next step is to add GPG keys for docker

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

Once the key is added, we can docker repository to apt sources.

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

Install Docker

Before installing docker, you should update apt package index.

sudo apt update

Now you can install docker-ce and other packages.

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

You would probably need docker-compose also.

sudo apt install docker-compose

Verify Installation

Docker provides a hello-world test image to for testing and verification. Lets start a container using this image to verify our installation.

sudo docker run hello-world

This will pull the hello-world image and run it for you.

Configure Docker of Non-root Users

You may have noticed a sudo before the last command. We need root permissions to run docker containers. In this step, we are going to remove that little inconvenience.

Add a group for docker.

sudo groupadd docker

If you get an error saying the group already exists, that is alright. Just ignore the error and proceed to next step.

Now we have to add your user account to docker group.

sudo usermod -aG docker $USER

Log out from Ubuntu and log in back again. You should be able to run docker without root privileges. Verify it using the hello-world image.

docker run hello-world

If this throws a permission denied error, you would probably need to restart your Ubuntu.

Configure Docker to Start During Boot

We are going configure docker to start when Ubuntu boots. Run

sudo systemctl enable docker

You can verify docker running status using

sudo systemctl status docker

If you do not want docker to start during boot, you can disable it using

sudo systemctl disable docker

Posted on
Category: Linux
Tags: Docker, Docker compose, Ubuntu