Docker is an open-source project that gives us the ability to easily run applications in isolated containers. Those who are using Ubuntu 22.04 LTS and want to install Docker CE to run containers of various Linux apps can follow this tutorial.
Another benefit of Docker containers is they can build on one another and communicate with one another. Examples of these applications would be an Apache server or a MySQL database.
As compared to normal virtual machines we do not need every container to run a complete operating system. I mean if we want to run a separated web server from the database server, we would have to start two complete virtual machines including the operating system. This is not the case with docker, in it, the underlying kernel will be the same and two independent containers can be started for respective servers without installing the full-blown operating system instead a lightweight Docker image will do the work.
Furthermore, Docker is a cross-platform project hence regardless of the OS (Windows, Linux, or macOS) it runs the command the will be the same for all and there will not be any compatibility issues between the containers.
Steps to install Docker CE on Ubuntu 22.04 LTS Jammy Jellyfish
1. System update and install a few tools
sudo apt update sudo apt install ca-certificates curl apt-transport-https
2. Add GPG Key
To download the packages of Docker on Ubuntu, we need to add the GPG key used to sign the Docker packages by its developer otherwise the system will return an error and not be able to use the repository.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
3. Add docker repository on Ubuntu 22.04
We can install the docker using Ubuntu Jammy’s default system repository, however, the version available will not be the latest one. Hence, add the official repository of Docker manually using the given block of command below.
Copy-paste the whole block of command in your terminal:
echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" \ | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
4. Install Docker Engine on Ubuntu 22.04
Finally, we have configured all the required things we needed. Now, simply run the system update command to refresh the repository cache and update already installed packages. After that use the APT packages to get all the Docker tools we need to start creating containers.
sudo apt update sudo apt-get install docker-ce docker-ce-cli containerd.io
To check the Docker service is running:
systemctl status docker
In case, it is not running, then use:
sudo systemctl start docker
5. Use docker without sudo
Once the installation is completed, we need to add our current system user to the Docker group otherwise every time we need to use ‘
sudo‘ with every command of the Docker.
sudo usermod -aG docker $USER newgrp docker
To check the version:
6. Create Container
Now, we can start creating our first container. For example, let’s say you want to create a Debian Bullseye container. For that, we will pull its docker image.
docker pull debian
docker create -it --name test debian
docker start test
Get the command line of the installed container:
docker attach test