How to Install Docker on Ubuntu 18.04 LTS Bionic Beaver


Docker is an open source container software that helps to deploy, run applications in a container. The containers are similar a virtual machine but consume fewer resource, easier to manage and will always run the same regardless of operating system environment it is running in.

Docker uses cgroups and namespace to allow the independent containers to run within a single Linux instance.

This post will help you to install Docker on Ubuntu 18.04.

Docker requires 64-bit operating system and supports Ubuntu 18.04 LTS.

Install Docker on Ubuntu 18.04 LTS

You can either choose to install Docker from the Ubuntu base repository or Offical Docker repository. The version of Docker package available in the Ubuntu base repository is a bit older than the version available in the official repository.

Install Docker from Ubuntu Repository

You can use apt-get command to install the Docker from Ubuntu base repository.

sudo apt install

Start the docker service and enable it to start automatically on system startup.

sudo systemctl start docker
sudo systemctl enable docker

Now, verify the docker version.

docker --version


Docker version 17.12.1-ce, build 7390fc6

Install Docker from Official Docker Repository

Docker is now available in two editions,

  • Community Edition (CE)
  • Enterprise Edition (EE)

Here, we will install Docker Comunity Edition (CE).


Uninstall the older versions of Docker package, named docker or docker-engine or along with associated dependencies.

If the system does not have Docker packages, skip the below step.

sudo apt -y remove docker docker-engine

Contents such as images, volumes, and networks under /var/lib/docker/ are preserved.

Setup Docker Repository

Update the repository cache.

sudo apt update

Install the below packages to ensure the apt work with https method, and CA certificates are installed.

sudo apt install -y apt-transport-https software-properties-common ca-certificates curl wget

Add the GPG key for Docker repository on your system.

sudo apt-key add gpg

Now, add the official Docker repository by running the below command in the terminal.

echo "deb [arch=amd64] bionic stable" | sudo tee /etc/apt/sources.list.d/docker.list

Update the apt database.

sudo apt update

Make sure you are installing the docker package from the official repository.

sudo apt-cache policy docker-ce


  Installed: (none)
  Candidate: 18.03.1~ce~3-0~ubuntu
  Version table:
     18.03.1~ce~3-0~ubuntu 500
        500 bionic/stable amd64 Packages

Install Docker CE on Ubuntu

Now, install the Docker using the following command.

sudo apt install -y docker-ce

Now you have Docker installed on your machine, start the Docker service in case if it is not started automatically after the installation

sudo systemctl start docker
sudo systemctl enable docker

Verify the Docker version.

docker --version


Docker version 18.03.1-ce, build 9ee9f40

Run Docker Containers

Run a docker container using the docker run command to download and start the container.

sudo docker run hello-world

Output: This confirms us that Docker is correctly installed.

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete 
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

Here are some interesting tutorials for you to get started:

1: Working with Docker Container – Top Important Docker Commands

2: Working with Docker Images – How to Build Docker Images

3: How to Build Docker Images with DockerFile

Allow Non-root user to run Docker

By default, normal users (non-root) would require a privilege equivalent to root to run docker commands. So, you have to run docker commands with sudo or give them privileges to run a Docker.

Follow the below steps to grant privileges equivalent to the root user for running the docker commands.

Create a group called docker if it does not exist.

sudo groupadd docker

Add your user to docker group, replace “raj” with your username.

sudo useradd raj

Add a user to docker group.

sudo usermod -aG docker raj

Log out and log back in.

You can now execute Docker commands without prefixing sudo.

$ docker run hello-world

That’s All.

You might also like