How to Install Docker on Ubuntu 18.04

Install Docker Ubuntu

Docker is a lightweight operating-system-level virtualization solution that allows you to run multiple containers simultaneously on a single host or across a fleet of servers with the help of Orchestration tools. Docker containers are isolated from each other using Kernel Control Groups and Namespaces.

In this tutorial post, we'll look at the different ways to install docker on Ubuntu 18.04 LTS.

Docker provides an image-based deployment model which makes it easy to package an application with its all dependencies and share across multiple environments. Docker also automates the deployment of applications inside this container environment. Before we look at the installation and usage of Docker, let's define some terms which are common in the world of Docker containers.

  • Docker Engine: This is a server daemon that manages all Docker objects - Networking, containers, storage, images e.t.c. Docker Engine also provides REST API used by applications to communicate with the daemon.
  • Docker Image - An image is a read-only template used to create containers on docker engine.
  • Container - This is a running instance based on Docker image. Each container has a unique ID
  • Registry - Docker registry is storage for already created images. It can be a restricted repository (private) or a public repository.

Docker Installation on Ubuntu

There are three ways to install Docker on Ubuntu 18.04, namely:

  1. Installing Docker from apt repository
  2. Installing Docker from the compiled Debian package
  3. Installing Docker edge using automation script

1) Installing Docker from apt repository

Before we add Docker repository, ensure there are no older packages of docker, unless you want to do upgrade instead of fresh installation.

$ sudo apt-get remove docker docker-engine

Note that the Docker CE package is now called docker-ce.

Install dependency packages

To allow apt to use a repository over https, install the packages below:

$ sudo apt-get install  software-properties-common ca-certificates apt-transport-https

Once the installation is successful, proceed to add docker apt repository.

Import official Docker gpg key

To install docker signed packages, you need to import gpg key:

$ sudo curl -fsSL | sudo apt-key add -

Add docker-ce stable repository

Now let's add docker repository using add-apt-repository command.

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

Hit:1 bionic-security InRelease
Hit:3 bionic InRelease 
Get:2 bionic InRelease [64.4 kB] 
Hit:4 bionic InRelease 
Get:5 bionic-updates InRelease [83.2 kB] 
Hit:6 bionic InRelease 
Get:7 bionic-backports InRelease [74.6 kB] 
Hit:8 stretch InRelease 
Fetched 222 kB in 1s (149 kB/s)
Reading package lists... Done

Above command will add a line to /etc/apt/sources.list

deb [arch=amd64] bionic stable

This is where docker packages will be downloaded from.

Update apt index and install docker

Once the repository has been added to the system

$ sudo apt-get update
$ sudo apt-get install docker-ce

Start and Enable Service to start on Boot

With installation being successful, you should be able to start docker service using systemctl command.

$ sudo systemctl start docker
$ sudo systemctl enable docker
$ sudo systemctl is-enabled docker

Check the status of the service using:

$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
 Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
 Active: active (running) since Tue 2018-06-05 19:37:30 UTC; 39min ago
 Main PID: 4235 (dockerd)
 Tasks: 18
 CGroup: /system.slice/docker.service
 ├─4235 /usr/bin/dockerd -H fd://
 └─4284 docker-containerd --config /var/run/docker/containerd/containerd.toml

Jun 05 19:37:30  dockerd[4235]: time="2018-06-05T19:37:30.458294292Z" level=warning msg="Your kernel does not support swap memory limit"
Jun 05 19:37:30 dockerd[4235]: time="2018-06-05T19:37:30.458346988Z" level=warning msg="Your kernel does not support cgroup rt period"
Jun 05 19:37:30 dockerd[4235]: time="2018-06-05T19:37:30.458358517Z"

Running Docker as a non-root user

If you would like to use Docker as a non-root user, you should now consider adding your user to the “docker” group with something like:

$ sudo  getent group docker
$ sudo usermod -aG docker <username>


$ sudo usermod -aG docker jmutai

For immediate group change without having to log out run:

$ sudo gpasswd -a username groupname


$ sudo gpasswd -a jmutai docker

2) Installing Docker .deb package

An alternative installation method is downloading the latest release of Docker for Ubuntu 18.04. The problem with this method is that you need to download a new file each time you want to upgrade Docker CE.

Head over to, choose your Ubuntu version, and browse to pool/stable/ then choose your OS architecture. You need to download the .deb file for the Docker version you want to install.

Install the package by running the command:

$ sudo dpkg -i /path/to/package.deb

3) Installing Docker edge version using a script

Docker provides convenience scripts at for installing edge versions of docker. This version is not recommended for production purposes but can be used for test and general purpose. Note that the scripts require root or sudo privileges to run:

$ curl -fsSL -o
$ sudo sh

The script will do everything for you, no manual work needed. Only that if you would like to use Docker as a non-root user, you should now consider adding your user to the "docker" group with something like:

$ sudo usermod -aG docker your-user

Check docker version installed using docker version command:

$ sudo docker version
Version: 18.05.0-ce
API version: 1.37
Go version: go1.9.5
Git commit: f150324
Built: Wed May 9 22:16:13 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm

Version: 18.05.0-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.5
Git commit: f150324
Built: Wed May 9 22:14:23 2018
OS/Arch: linux/amd64
Experimental: false

Using Docker on Ubuntu

Now that we have everything we need ready, let's consider few docker operations to help you get started. We'll download two docker images, then create containers from them. Then later destroy these containers.

By default, docker images are downloaded from docker public repository, no authentication needed to pull publicly shared images. Let's download Ubuntu 18.04 and CentOS 7 image. The docker pull command is used for this:

$ sudo docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
a48c500ed24e: Pull complete 
1e1de00ff7e1: Pull complete 
0330ca45a200: Pull complete 
471db38bcfbf: Pull complete 
0b4aba487617: Pull complete 
Digest: sha256:c8c275751219dadad8fa56b3ac41ca6cb22219ff117ca98fe82b42f24e1ba64e
Status: Downloaded newer image for ubuntu:18.04

$ sudo docker pull centos:latest
latest: Pulling from library/centos
7dc0dca2b151: Pull complete 
Digest: sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa5322
Status: Downloaded newer image for centos:latest

Check images available:

$ sudo  docker images
centos         latest  49f7960eb7e4   22 hours ago  200MB
ubuntu         18.04   452a96d81c30   5 weeks ago   79.6MB

Create a container from Docker image

The docker run command is used to run docker container.  A container is a running instance of a docker image. It is also possible to create a custom docker image using Dockerfile. Refer to the link for how to write your own Dockerfile.

The example below will create a container named ubuntu18.04 from Ubuntu 18.04 image downloaded earlier.

$ docker run -it --rm --name ubuntu-cont ubuntu:18.04 /bin/bash

The options used are:

  • -it : Get interactive shell session
  • --rm : This instructs docker to delete container on exit
  • --name: Used to specify the name of the container. The name given is ubuntu-cont
  • ubuntu:18.04: This is the name of docker image we're creating a container from
  • /bin/bash : Command to execute on the container

If you exit from container shell using exit command or ctrl+d

Read also:

With running Docker engine, you can begin playing with docker to understand its ins and outs. We have good guides on Linoxide to help you get started. Docker documentation is also a good place to start.

3 Comments... add one

  1. I notice that you also received warnings in your status message... i.e. level=warning msg="Your kernel does not support swap memory limit"

    Do you know why these warnings occur on a fresh install into a stable (18.04 Ubuntu LTS) OS?


Leave a Comment