Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  VPS FAQ  >  How to Install Docker on Ubuntu?

How to Install Docker on Ubuntu?

 3 min

Docker is one of the most popular tools when it comes to containerizing an application. Docker lets you build an application in a container that can be deployed in any environment. Because Docker maintains the consistency and similarity among various environments, developing, testing and deploying an application becomes easier.

In this guide, we will show you how to easily set up Docker on an Ubuntu server using the official Docker repository. You will have to perform the installation through the command line with a sudo user.

Prerequisites

To install Docker on an Ubuntu server, you will need to satisfy the following requirements:

  • Ubuntu 64 bit
  • A user with sudo rights
  • Internet connection

Update Ubuntu Packages

Update your package list, install packages, and add Docker’s repository.

Execute the following commands one after the other in the terminal:

sudo apt update

sudo apt install ca-certificates curl -y

The parameters – ‘ca-certificates’ and ‘curl’ respectively represent the package that allow your system to verify secured HTTPS connections, and the package used to download Docker’s GPG key.

Import Docker’s GPG key

Using Docker’s GPG key ensures that packages downloaded from Docker repositories are not tampered with.

Create a keyring directory and get the Docker signing key.

sudo mkdir -p /etc/apt/keyrings

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg \

-o /etc/apt/keyrings/docker.asc

sudo chmod a+r /etc/apt/keyrings/docker.asc

Add Docker’s key to the system keyring which Ubuntu will use to validate Docker packages.

Add the Docker Repository

Then add the Docker’s official APT repository to the Ubuntu system.

echo \

  "Types: deb

  URIs: https://download.docker.com/linux/ubuntu

  Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")

  Components: stable

  Architectures: $(dpkg --print-architecture)

  Signed-By: /etc/apt/keyrings/docker.asc" | \

  sudo tee /etc/apt/sources.list.d/docker.sources > /dev/null

Update Ubuntu’s package list again after adding the repository: 

sudo apt update

Using Docker’s official repository ensures you install the latest stable Docker packages providing for the Ubuntu release.

Install Docker

Now install Docker Engine along with the Docker CLI, container runtime, Buildx, and Docker Compose plugin. 

sudo apt install docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin -y


The installation takes a couple of moments. Once completed, Docker’s service should be available on the server. 

You can launch Docker manually in case of its unresponsiveness: 

sudo systemctl start docker

Ensure Docker starts automatically whenever the server boots, run: 

sudo systemctl enable docker

Check the Docker Installation

Verify the Docker installation stats by checking its version through command: 

docker –version

For an additional test, run Docker’s official hello-world image: 

sudo docker run hello-world

If Docker functions properly, the command will download the image and display a confirmation message. It confirms that Docker downloads images and creates containers successfully. 

Run Docker Without sudo

By default, Docker commands need sudo. If you want to run Docker as a regular user, add the user to the Docker group: 

sudo usermod -aG docker $USER

Log out to the server for the group change to take effect. Then test Docker again:

docker run hello-world

You can run Docker commands without adding sudo.

Note: Membership in the Docker group provides root-level privileges on the host. Only add trusted users to this group.

Useful Docker Commands

There are some helpful Docker commands to use after the installation.

To Check Running Containers

docker ps

To track running and stopped containers:

docker ps -a

Download a Docker Image

For instance, if you want to download the Nginx image:

docker pull nginx

Design and launch a Container

When users run them, the images will be launched: 

docker run -d --name webserver -p 8080:80 nginx

It will run Nginx in the background and map your server’s port 8080 to port 8 in the container.

Stop a Container

docker stop webserver

Create a Stopped Container

docker start webserver

View Downloaded Images

docker images
Conclusion

Docker simplifies deploying apps in isolated and consistent environments. Docker Engine and Docker tools like Docker Compose and Buildx are installed as part of Docker through its official Ubuntu repository.

After installing Docker, you can download images, build containers and deploy applications on your Ubuntu server.

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.