How to Install Docker on Ubuntu 22.04 [Important Commands]

0

So it’s 2022 and the new version of Ubuntu 22.04 LTS has been released with its new cool features, there are lots of things to install in the new Ubuntu 22.04 that also includes Docker on Ubuntu 22.04.

With the new release of Ubuntu, we have to install Docker on Ubuntu 22.04. and here you can find a detailed explanation of How to Install Docker on Ubuntu 22.04. Docker Desktop for Linux provides Linux desktop developers with the same local development experience as others using Docker Desktop for macOS and Windows, including accessibility to the most recent features including Docker Extensions.

Install Docker on Ubuntu 22.04

Here are the step-by-step processes to install docker on Ubuntu 22.04.

Before installing the Docker Desktop on your Ubuntu your system has to meet so requirements. So here are the requirements to install Docker on Ubuntu 22.04

Prerequisites

To successfully install docker you have to make sure of the following:-

  • Your machine must have to meet the system requirements.
  • You must have a 64-bit version of Ubuntu 22.04 lts version cause Docker Desktop only supports x86_64 and amd64 architecture.
  • You have to uninstall the beta version of Docker Desktop in Linux.

To-Do that run:

$ sudo apt remove docker-desktop

To completely remove the configurations and data files at $HOME/.docker/desktop, and the symlink at /usr/local/bin/com.docker.cli with the remaining systemd service files. Run:

$ rm -r $HOME/.docker/desktop
$ sudo rm /usr/local/bin/com.docker.cli
$ sudo apt purge docker-desktop

Especially for those who do not have a Gnome Desktop Environment they must have to install the gnome-terminal. To-Do that run the following command.

$ sudo apt install gnome-terminal

Installation of Docker

These are the recommended way to install docker on Ubuntu;

  1. Set up Docker’s package repository on your system.
  2. You have to download the latest DEB package from the release page of Docker.
  3. Now Install the required package with apt as follows:
$ sudo apt-get update
$ sudo apt-get install ./docker-desktop-<version>-<arch>.deb

*Note

You might get an error message at the end of the installation process depending on the machine. Please ignore if this type of error is shown in the output.

N: Download is performed unsandboxed as root, as file '/home/user/Downloads/docker-desktop.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)

After installing docker there are a few install configurations that must be done through the post-install script of the deb package.

The post-install script of the deb package includes:

  • Sets the resource limits and the capability on the Docker Desktop binary to map privileged ports.
  • Adds a DNS name for Kubernetes to /etc/hosts.
  • Creates a link from /usr/bin/docker to /usr/local/bin/com.docker.cli.

Test your Docker installation

To launch Docker Desktop for Linux, navigate to the Applications menu and choose Docker Desktop. This opens the whale menu icon and clicks on that to open the Docker Dashboard and the reporting status of the Docker Desktop.

There is an alternate way to do that, run the following command.

$ systemctl --user start docker-desktop

When Docker Desktop begins, it generates a dedicated context for usage as a target by the Docker CLI and makes it the present context in use.

This is done to avoid a conflict with a local Docker Engine running on the Linux host and utilizing the default context. Docker Desktop returns the present context to the previous one upon shutdown.

Docker Desktop updates the Docker Compose and Docker CLI binaries on the host and it helps to install Docker Compose V2 on your system and allows users to link it from the Settings panel as docker-compose. The cloud-integration capabilities are included the new Docker CLI binary and Docker Desktop installs the Docker CLI and in /usr/local/bin it creates a symlink to the classic Docker CLI at /usr/local/bin/com.docker.cli

After successfully installing the Docker, anyone can easily check the version of these binaries by running the below code in their terminal

$ docker compose version
Docker Compose version v2.5.0

$ docker --version
Docker version 20.10.14, build a224086349

$ docker version
Client: Docker Engine - Community
Cloud integration: 1.0.24

If you want to enable Docker Desktop to start on login, you have to make some changes by going to the Docker menu, selecting Settings> General> Start Docker Desktop when you log in.

You can also do it by running the below code in the terminal

$ systemctl --user enable docker-desktop

And to stop Docker you have to click on the whale menu tray icon and that will open the docker menu and it will select Quit Docker Desktop.

You can also do that using terminal by running the following code:

$ systemctl --user stop docker-desktop

Upgrade Docker Desktop on Ubuntu 22.04

You can also upgrade Docker after the new version is released. To do that the Docker UI will notify you by showing a notification. To upgrade it you have to download the package each time and run:

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

How to uninstall Docker on Ubuntu 22.04

To easily remove the Docker from your Linux just run the below code:

$ sudo apt remove docker-desktop

If you want to completely remove the configuration and the data files at $HOME/.docker/desktop, the symlink at /usr/local/bin/com.docker.cli, and the remaining systems service files.

Run the following code:

$ rm -r $HOME/.docker/desktop
$ sudo rm /usr/local/bin/com.docker.cli
$ sudo apt purge docker-desktop

Now you have to remove the credsStoreand currentContextproperties from $HOME/.docker/config.json. But you have to delete any edited configuration files manually.

Important Docker Commands

1. docker search

You can use this command to search for public images.

$ docker search MySQL

2. docker pull

By using this command you can have multiple images under one repository, and you can pull all the images.

$ docker pull --all-tags mysql

3. docker images

By running this command we can list all the images in our local machine.

$ docker images

4. docker run

After some images, you can now create a container by running the following command.

$ docker run --env MYSQL_ROOT_PASSWORD=my-secret-pw --detach mysql

5. docker ps

By using this command you can list all the running containers.

$ docker ps --all

6. docker stop

It helps to stop the specific container.

$ docker stop <container id>

7. docker restart

It helps to restart the specific container.

$ docker restart <container id>

8. docker rename

It helps to change the container name from compassionate_fermi  to test_db.

$ docker rename compassionate_fermi test_db

9. docker exec

It helps to Access the running container test_dbby running the following command.

$ docker exec -it test_db bash
$ mysql -uroot -pmy-secret-pw
$ SHOW DATABASES;

10. docker logs

This will help you to debut your Docker container and it will also fetch logs from the specified container.

$ docker logs test_db

Read More: How to Install Docker on Ubuntu 20.04 Easily

Closing thought

So Docker is one of the best open platforms for developing and running applications and with the new Ubuntu.lts version you need to install Docker on Ubuntu 22.04 for a better and smooth experience.

Docker is the software that helps to host a container called Docker Engine with images that helps you to create applications more ease.

LEAVE A REPLY

Please enter your comment!
Please enter your name here