Header Ads

How to Install Docker on Ubuntu?

How to Install Docker on Ubuntu

Docker is a popular containerization technology that allows developers to create, deploy, and run applications in a self-contained environment. In this tutorial, we will show you how to install Docker on Ubuntu.

Prerequisites:

Before we begin, you will need to have access to a Ubuntu server or desktop with sudo privileges.

Step 1: Update Package Repository

First, we need to update the package repository to ensure that we have the latest version of Docker.

To do this, open a terminal window and enter the following command:

sudo apt update

Step 2: Install Docker Dependencies

Next, we need to install the dependencies required for Docker to run.

To do this, enter the following command:

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

Step 3: Add Docker GPG Key

We now need to add the Docker GPG key to the system.

Enter the following command to download and add the key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Step 4: Add Docker Repository

Once we have added the key, we need to add the Docker repository to the system.

Enter the following command to add the repository:

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

Step 5: Install Docker

Now that we have added the repository, we can install Docker.

Enter the following command to install Docker:

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

Step 6: Verify Docker Installation

Once the installation is complete, we can verify that Docker is installed correctly by running the following command:

sudo docker run hello-world

This will download a test image and run it in a container.

If everything is working correctly, you should see the following message:

Hello from Docker!
This message shows that your installation appears to be working correctly.

Step 7: Manage Docker as a Non-root User

By default, Docker commands can only be run by the root user. However, it is recommended to use Docker as a non-root user for security reasons.

To allow a non-root user to use Docker, you can add the user to the docker group.

Enter the following command to add the current user to the docker group:

sudo usermod -aG docker ${USER}

Then, log out and log back in for the changes to take effect.

Step 8: Conclusion

In this tutorial, we have shown you how to install Docker on Ubuntu. You can now use Docker to create, deploy, and run applications in a self-contained environment.

Related Searches and Questions asked:

  • Docker Storage Explained
  • How to Install Docker on Windows?
  • Docker Compose Explained
  • Docker Logging Explained
  • That's it for this post. Keep practicing and have fun. Leave your comments if any.

    Powered by Blogger.