How to install Docker in Ubuntu

How to install Docker in Ubuntu

In this article i will share with you how to install Docker in Ubuntu server with just a few commands also i will provide some tips and tricks that will make you life easier in terms of using Docker.

What is Docker?

Docker is a platform designed to make it easier to create, deploy, and run applications in isolated environments called „containers”.

„Containers” permits a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.

The cool thing about containers is the fact that they are isolated from each other and you are in complete control of the resources they share.

Also by doing so, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

How to install Docker in Ubuntu: What do you need?

  • A PC with a CPU that supports virtualization
  • 4GB of RAM (recommended 8GB)
  • Ubuntu or Ubuntu Server 22.04 LTS (minimum)

Commands to Install Docker CLI in Ubuntu

I personally use Docker CLI and manage my containers with Portainer.

I will show you this method first then will install the Docker Desktop for Ubuntu. The following method is the longest in terms of installation time, in a sense that you will have to enter more commands in the terminal.

Open a terminal window.

First we need to update & upgrade the current packages on our system.

sudo apt update&& sudo apt-get upgrade

Next you need to add the Docker repository in your Ubuntu installation.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

In some situations (most of the time) you need also the following dependencies for Docker to run on your Ubuntu machine.

sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y

The final step is to install Docker via the following command.

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

Optional step: I recommend also to add your user to the Docker grup so you dont have to invoke SUDO each time you need to run a command.

When you add your user to the Docker group, you’re essentially granting it permission to interact with Docker without needing to be root.

This procedure is security related – because in some situations it can lead to security issues – but its not mandatory.

This can improve your workflow by allowing you to run Docker commands more conveniently and without the risk of accidentally executing dangerous commands as the root user.

sudo usermod -aG docker your_username

Optional step: I also recommend to install Portainer.

Portainer is an open-source tool for managing containerized applications in Docker environments. It provides a graphical user interface (GUI) that allows users to easily deploy, manage, and monitor Docker containers, images, volumes, networks, and other Docker-related resources.

Will install Portainer CE (Comunnity Edition).

A volume must be created to store all the Portainer data.

docker volume create portainer_data

Now run the following command to install Portainer, then you can acces Portainer via port 9443.

docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

Install Docker Desktop on Ubuntu

Before we can install Docker Desktop on Ubuntu, we need to run some commands.

Basically we are setting the repository for Docker. This step is necessary on the new machines, because afterward we can install and also update Docker directly from the repository.

Open the termina.

First commad:

sudo apt-get update

After the update is pulled install Ca Cartificates to insure a secure connection with the 3rd party Docker servers.

sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /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

Now we need to add the repository to the Apt sources with the command:

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

And finally do another update.

sudo apt-get update

After all this is done, now you can download the latest DEB package for Docker and then run the following command.

sudo apt-get install ./docker-desktop-<version>-<arch>.deb

Make sure to CD in the directory you’ve downloaded the DEB package and replace in the command above the <version> and <arch> according to your file.

Dan Mutu este fondatorul și editorul șef la GeekChronicles.ro. Contribuitor activ la secțiunile revistei Geek Chronicles și la secțiunea de Forum. Cunoștințele predominante sunt în domeniile: tehnologiei, marketing și suport tehnic.
Geek Chronicles

Pasionat de tehnologie?

Te invităm în grupul nostru de Facebook unde purtăm discuții constructive despre tehnologie și nu numai.

Articole direct pe mail săptămânal

Îți trimitem săptămânal un email cu toate articolele/materialele noi publicate fără spam

Prin abonare confirmați că ați citit termenii și condițiile și aveți peste 16 ani