How to install Docker on Ubuntu 18.04?

Docker is an open-source platform that helps to automate the deployment, testing, and scaling of applications inside containers. It's becoming increasingly popular among developers due to its flexibility and ease of use. In this article, we will learn how to install Docker on Ubuntu 18.04.

Prerequisites

Before we begin, make sure you have a user account with sudo privileges. If you don't have one, create one using the following command

sudo adduser your_username

After adding the user account, add the user to the sudo group using the following command

sudo usermod -aG sudo your_username

Step 1: Update the system

Before installing any new package, it's always a good practice to update the system. Run the following command to update the system

sudo apt-get update

Step 2: Install Docker

To install Docker on Ubuntu, follow the steps below,

Add the Docker GPG key using the following command

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the Docker repository to the apt sources list using the following command

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Update the apt package list to include the newly added repository.

sudo apt-get update

Finally, install Docker CE (Community Edition) using the following command

sudo apt-get install docker-ce

Step 3: Verify the installation

After the installation is complete, you can verify it using the following command

sudo docker run hello-world

This command will download a test image and run it in a container. If everything works fine, you should see a message indicating that Docker is installed and working correctly.

Step 4: Manage Docker as a non-root user

By default, the Docker daemon runs as the root user. It's not recommended to run Docker as a root user because it can cause security issues. To avoid this, you can manage Docker as a non-root user.

Add your user to the docker group using the following command

sudo usermod -aG docker your_username

Log out and log back in to apply the changes.

Verify that you can run Docker commands without sudo

docker run hello-world

Conclusion

In this article, we learned how to install Docker on Ubuntu 18.04. We also learned how to verify the installation and manage Docker as a non-root user. Docker is a powerful tool that can simplify the deployment of applications and improve the efficiency of your development environment. With Docker, you can easily create isolated environments for your applications and ensure that they run consistently across different platforms.


How to install Docker on Ubuntu 20.04?

Comments

Popular posts from this blog

How to update build number in Azure DevOps pipeline?

How to get latest build ID from Azure DevOps pipeline?

How to install AWS System Manager (SSM) Agent on windows using PowerShell?