Phone :  +370 (5) 204-1903
Email :  sales@1gbits.com
  1. Dedicated server
  2. Blog
  3. How to install docker on Ubuntu

How to install docker on Ubuntu

In the last few years, Docker has gained popularity to create containers for application deployment. Docker is an open-source technology that uses containers to contain and run different and individual microservices within it. It helps a lot for the DevOps team to manage their delivery pipeline with great automation. Many organizations that have implemented the DevOps approach are using Docker technology. Docker is very well familiar with the virtual machines, but containers ensure the portability that depends on the host operating system. 

Ubnutu Tutorials Sep 26, 16 by admin 10 min Read
How to install docker on Ubuntu


With the help of Docker, you can easily bridge the gap between the developers and the IT operation team. It helps the team make small changes in the ongoing application at any phase of the development without impacting the whole system. With Docker, there is transparent communication among team members. To run an image, you will need a virtual machine, but with Docker, you do not have to worry about the requirements that make it a perfect fit for VPS projects. Docker is available in two versions- Docker CE (Community Edition) and the Docker EE (Enterprise Edition); you can choose Docker CE for small enterprise projects.

You can easily install your favourite Docker version of any of the Linux distributions. Below is the documentation on how you can install Docker on Ubuntu 18.04. The guide will also work for Ubuntu 16.04 and 20.04.

Prerequisites for Docker

Below are prerequisites for installing Docker on the Ubuntu OS.

  • An Ubuntu 16.04, 18.04 or 20.04 64-bit operating system.
  • Create a user account for using Docker with Sudo privileges.
  • You should have a command-line/terminal (CTRL-ALT-T or Applications menu > Accessories > Terminal) for running Docker installing and setup commands.
  • You will require repositories for Docker software (optional).

Follow the Below-Mentioned Steps to Install Docker on Ubuntu.

If you have a Docker installation package in the official Ubuntu repository, check for the latest version. Before starting, you must ensure that the latest version is installed from the official Docker repository. A new package source and GPG key are added to ensure validated download. After that, we can install the packages. Below are the steps and commands.

Step1- Updating an Existing List of Packages

We need to make sure that the system and packages are updated to make the system reliable for Docker installation using the below commands.

sudo apt update

sudo apt upgrade


Step 2- Installing a Few Prerequisite Packages

Before installing Docker, we need to install the required packages using the below single command.

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


  • apt-transport-https – this part of the above command will ensure that the package manager will transfer the files and data over HTTPS
  • ca-certificates – will allow that the web browser and your machine to check for security certificates
  • curl – transfers data
  • software-properties-common – it will add scripts to manage the software

Step 3- Adding the GPG Key

You can add the GPG key for the Docker repository using the below command. (If the command doesn’t work, try removing the ‘-‘ at the end)

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

Step 4- Adding the Docker Repository to APT Sources

Adding the repository to apt sources will ease the installation process and ensure we use the official method to install Docker using the below command.

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

Step 5- Package Database Update 

Update the package from the above newly added repository packages 

sudo apt update

Step 6- Making Sure the Installation of the Official Docker Repo 

apt-cache policy docker-ce

After running the above command, you will get the output, but you may get a different Docker's version. Here note down the version that you want to install because you will need it in the next section.

We recommend the latest version of docker to be installed. You can find that on the Candidate section.

Step 7- Install Docker

sudo apt install docker-ce=<VERSION>

Step 8- Check for Docker Running Status

sudo systemctl status docker

Step 9- Starting Docker

You can use the below commands to run the Docker.

sudo systemctl start docker

sudo systemctl enable Docker

Step 10- Verify the Installed Docker Version.

Verify for the installed Docker version by using the below command.

docker --version

How to Execute Docker Commands Without sudo Access (optional)?

You can run the Docker command using the root user or the Docker group user. The group user is automatically created during the installation process. If you are running the Docker command without mentioning the sudo or the group user, you will get the below output.

docker container run hello-world

See 'docker run --help'

To avoid the above error, you must add your working user to the Docker group with the below command's help.

sudo usermod -aG docker ${USER}

To enable the changes, you can log out and log in to the server or use the below command.

su - ${USER}

Once you run the above command, you will be asked to provide your user's password to continue. The below command will confirm if your user is added to the docker group or not.

id -nG


sammy sudo docker

If you want to add another user to the docker group, you have to mention the username explicitly using the below command.

sudo usermod -aG docker username

Using the Docker Commands

With the Docker commands' help, you can pass options and commands followed by arguments using the below Docker syntax.


docker [option] [command] [arguments]

Docker's available subcommands-

Below is the list of Docker subcommands-

Attach- this command will allow you to attach local standard input, output, and generated error streams to a running container within a Docker.

Build- this command will allow you to create an image from the available Dockerfile

Commit- this command will create a new image from a change within a container.

Cp- it will allow you to copy files/folders between the local filesystem and container

Create- this command will create a new container.

Diff- this command will inspect any changes done to files or directories within a container's filesystem

Events- it will provide you with real-time events from the server.

Exec- it will help in running a command to run a container

Export- it will allow you to export a container's file system in the tar archive.

History- it will display the images' history.

Images- it will list all the available pictures.

Import- it will allow you to import the tarball's content to create a filesystem image.

Info- it will display the complete system's information.

Inspect- it will provide you with a Docker Object's low-level information.

Kill- it will allow you to kill containers.

Load- it will allow you to load an image from a tar archive. 

Login- using this command, you can log in to a Docker registry.

Logout- it will log you out from a Docker registry.

Logs- it will fetch the container's logs.

Pause- it will pause all processes within provided containers.

Port- it will list all the port mappings for the container.

Ps- this command will list all the available containers

Pull- it will help you to pull an image from a registry.

Push- it will allow you to push an image to a registry.

Rename- you can rename a provided container.

Restart- it will restart containers.

Rm- it will remove containers

Rmi- it will remove images.

Run- it will run commands within a new container.

Save- it will save images to a tar archive. 

Search- this command will search the image in Docker Hub 

Start- it will start stopped containers.

Stats- it will Display the usage statistics of container(s) resource. 

Stop- it will stop running containers.

To view specific subcommand

docker docker-subcommand --help

To view system-wide Docker's information.

docker info

Starting the Docker on Ubuntu 18.04 (16.04 or 20.04)

After the Docker installation, check if the test image works using the below command.

sudo docker run hello-world

You can use the below command to search for the available downloaded images.

sudo docker search [search_query]

sudo docker search ubuntu

The above command will search for the Docker Hub and return a list of all images whose names match the search string.

To pull the particular image to your machine, run the below command.

sudo docker pull ubuntu

You can check the list of all downloaded images to your computer using the below command.

sudo docker images


Using the above document, you will install and get started with your Docker on Ubuntu distribution. This will allow the developers to understand how the application will run outside the test environment. This will ease the work of the system admin to make system changes and search for libraries. You can follow step by step instructions to get started with your Docker application. You can simplify many working by automating the development and deployment process within your CD/CI pipeline.

Do you have any further tips or precautions to share while installing Docker in Ubuntu? Let us know in the comments. 

Save Save

author img


Leave A Comment