How to Install Docker And Docker Compose In Ubuntu 22.04 LTS
======
A Step By Step Guide To Install Docker Engine With Docker Compose In Ubuntu.
In this guide, we will see what is **Docker**, how to **install Docker Engine in Ubuntu** Linux. In addition, we will also see how to **install Docker compose**, a tool to define and run multi-container Docker applications.
This guide has been officially tested on Ubuntu 22.04 LTS. However, it should work on older versions such as 20.04 LTS, and 18.04 LTS. For better security and stability, I recommend you to use the most recent Ubuntu 22.04 LTS version.
### What Is Docker?
**Docker** is a fast, lightweight and OS level virtualization technology for developers and system administrators who wants to build an application with all of required dependencies, and ship it out as only one package.
Unlike other Virtualization methods, such as VMWare, Xen and VirtualBox, there is no need of separate guest operating system for each virtual machine.
All Docker containers efficiently share the host operating system's Kernel. Each container will run in an isolated userspace in the same operating system.
Docker containers will also run on any Linux variant. Let us say you're working in Fedora, and I am using Ubuntu. We can still develop, share and distribute the Docker images with each other.
You don't have to worry about the OS, software, customized settings, or anything. We can continue the development as long as we have Docker installed in our host system. Simply put, Docker will work everywhere!
You read two terms in the above paragraphs namely **Docker images** and **Docker containers**. You might wonder, what they are and what is the difference between them.
In layman's terms, a Docker image is a file which describes how a Container should behave, whereas Docker container is the running (or stopped) state of the Docker image.
Hope you got a basic idea about Docker. Refer official Docker user guide for more details. The link is attached at the end of this guide.
### Docker Requirements
To install and configure Docker, your system must meet the following minimum requirements.
1. 64 bit Linux or Windows operating systems.
2. If you're on Linux, the Kernel version should be 3.10 or above.
3. An user account with `sudo` privileges.
4. VT (virtualization technology) support enabled on your system BIOS. [Read: [How To Find If A CPU Supports Virtualization Technology (VT)][1]]
5. Your system should be connected to Internet.
In Linux, to verify the Kernel and architecture details, run the following command from the Terminal:
```
$ uname -a
```
**Sample Output:**
```
Linux Ubuntu22CT 5.15.35-3-pve #1 SMP PVE 5.15.35-6 (Fri, 17 Jun 2022 13:42:35 +0200) x86_64 x86_64 x86_64 GNU/Linux
```
As you see in the above output, my Ubuntu system's kernel version is**5.15.35-3-pve**and my Ubuntu system's architecture is **64 bit** (**x86_64 x86_64 x86_64 GNU/Linux**). Check the bold letters in the above result.
**Heads Up:** Here, I am using Ubuntu 22.04 container in **[Proxmox][2]**. This is why you see word "pve" in the kernel version in the above output. If you're using Ubuntu physical (or virtual) machine, you will see **5.15.35-3-generic** as kernel version.
Well, the Kernel version is higher than the minimum requirement, and the arch is 64 bit. So, we can install and use Docker without any problems.
Please note that it doesn't matter which Ubuntu OS you use. Also, It doesn't matter whether you use Ubuntu Desktop or Ubuntu Server edition or any other Ubuntu variants such as Lubuntu, Kubuntu, Xubuntu.
Docker will work just fine as long as your system has the Kernel version 3.10+, and your system's arch is 64 bit.
### Install Docker In Ubuntu 22.04 LTS
First of all, update your Ubuntu system.
#### 1. Update Ubuntu
Open your Terminal, and run the following commands one by one:
```
$ sudo apt update
```
```
$ sudo apt upgrade
```
```
$ sudo apt full-upgrade
```
#### 2. Add Docker Repository
First of all, install the necessary certificates and to allow apt package manager to use a repository over HTTPS using command:
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
```
![Run Hello World Docker Container][5]
Great! Docker is ready to use.
#### 5. Run Docker As Non-root User In Linux (Optional)
By default, the Docker daemon binds to a Unix socket instead of a TCP port. Since that **Unix socket is owned by the root** user, the Docker daemon will only run as the root user. Hence, the normal users can't perform most Docker commands.
If you want to run Docker as non-root user in Linux, refer the following guide:
* [How To Run Docker As Non-root User In Linux][6]
I personally do not use this and **do not recommend it** as well. If you don't expose your system to Internet, it is fine. However, do not run Docker as non-root user in production system.
### Install Docker Compose In Ubuntu
**Docker Compose** is a tool that can be used to define and run multi-container Docker applications. With Compose, you use a Compose file to configure your application’s services. Then, using a single command, you can create and start all the services from your configuration.
We can install Docker Compose using any one of the following methods.
#### Method 1 - Install Docker Compose Using Binary
Download the latest Docker Compose from [here][7].
As of writing this, the latest version was **2.6.1**.
Run the following command to download latest stable Docker compose file:
If a new version is available, just replace the number **v2.6.1** in the above command with the new version number. Please don't forget to preface **"v"** before the version number.
Finally, apply executable permissions to the binary using command:
```
$ sudo chmod +x /usr/local/bin/docker-compose
```
To check installed docker composer version, run:
```
$ docker-compose version
Docker Compose version v2.6.1
```
#### Method 2 - Install Docker Compose Using PiP
Alternatively, we can install Docker Compose using **PIP**. Pip is a python package manager used to install applications written in Python programming language.
Refer the following guide to install Pip on your system.
* [How To Manage Python Packages Using Pip][8]
Once pip installed, run the following command to install docker compose. The following command is same for all Linux distributions!
```
$ pip install docker-compose
```
After installing Docker Compose, you can check the version with command:
```
$ docker-compose --version
```
You will see an output something like below.
```
docker-compose version 2.6.1, build 8a1c60f6
```
Congratulations! We have successfully installed Docker Community Edition and Docker Compose.
I installed Docker, now what? Check the next article in this series to learn the Docker basics.
* [Getting started with Docker][9]
To install Docker in RPM based systems such as RHEL, Fedora, CentOS, AlmaLinux, Rocky Linux and openSUSE, check the following link.
* [Install Docker inCentOS][10]
### Conclusion
In this guide, we discussed what is Docker and how to install Docker in Ubuntu 22.04 LTS Jammy Jellyfish. Then we learned how to test docker installation by running a hello-world docker image. Finally, we concluded the tutorial by installing Docker compose using two different ways.