Docker is super easy software for developers to create, share, and run applications across different environments. It operates efficiently on local machines, virtual setups, and even in cloud environments.
Docker allows containers to create and modify files within their own dedicated storage space, which makes applications more flexible and customizable. Automates a variety of tasks with Docker, all for free.
This article will provide you with detailed instructions on how to install Docker on Ubuntu 22.04. Head over to this article if you are using the latest version of Ubuntu 24.04.
How to Install Docker on Ubuntu 22.04?
The provided steps can be followed to install Docker on Ubuntu 22.04.
Step 1: Install Dependencies
Before initiating the Docker installation, it’s essential to install the necessary libraries and dependencies:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y |
---|
The required dependencies for the Docker have been installed successfully on your machine.
Step 2: GPG Key for Docker
Adding a GPG key is an essential part of installing the docker engine from a trusted source:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg |
---|
Step 3: Add Docker Repository
After successfully obtaining the GPG key, add the repository for the Docker engine:
echo “deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu focal stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null |
---|
The blank output represents that the command executed without any errors and the GPG key has been added to the Docker repository.
Step 4: Update System Repository
Update your Ubuntu 22.04 system files. This step will ensure that all package files are up to date:
sudo apt update |
---|
The screenshot indicates that the operating system and installed programs have been updated to the latest versions.
How to Install Docker via APT Manager?
Here are some important steps to install Docker on your system via the APT package manager.
Step 1: Install Docker
Once all the prerequisites have been done successfully, your operating system is ready to install the Docker:
sudo apt install docker-ce docker-ce-cli containerd.io -y |
---|
The above command has unpacked and installed the Docker package files on your Ubuntu system.
Step 2: Confirm Docker Version
Run the –version option to confirm if the docker is installed properly:
docker –version |
---|
The currently installed version of Docker is 24.0.6.
Step 3: Run Docker
Run the command to test the Docker:
docker run hello-world |
---|
Oops! An error is encountered while testing the docker engine. Upcoming steps can be used to fix the error.
Step 4: Change Ownership
The chown is a simple command that can be used to change ownership of the “docker.sock” file:
sudo chown $USER:$USER /var/run/docker.sock |
---|
Step 5: Allow Users
Permit all users with chmod 666 to both read and write access to Docker:
sudo chmod 666 /var/run/docker.sock |
---|
Step 6: Restart Docker
Restart the Docker engine once you have run the aforementioned commands:
sudo service docker restart |
---|
The blank output confirms that the Docker service restarted successfully, without encountering any errors.
Step 7: Run Docker
Finally, test the Docker engine in the terminal to see if it returns hello-world in the output:
docker run hello-world |
---|
Congratulations! You have installed the Docker engine on your Ubuntu 22.04 version.
How to Remove Docker from Ubuntu 22.04?
You can uninstall Docker from Ubuntu 22.04 using these simple steps.
Step 1: Uninstall Docker
The purge option removes a package and its configuration files from your operating system, completely:
sudo apt purge -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras |
---|
No error in the output represents that Docker has been removed successfully from your Ubuntu 22.04 operating system.
Conclusion
Install Docker on Ubuntu 22.04 using the terminal. To set up Docker on Ubuntu 22.04, add the GPG key and then install by using the command “apt install -y docker-ce docker-ce-cli containerd.io“. This guide elaborated on the detailed process of setting up the environment and installing and removing Docker from Ubuntu 22.04.