πŸš€ How to Install Docker on Ubuntu Server (Step-by-Step Guide)

Docker has become an essential tool for developers, system administrators, and DevOps engineers. It allows you to run applications in lightweight containers, making deployments faster, more consistent, and easier to manage.

In this guide, you’ll learn how to install Docker on an Ubuntu server and get started with your first container.

🧠 What is Docker?

Docker is a containerization platform that enables you to package applications along with their dependencies into portable containers. These containers can run consistently across different environments.

πŸ”§ Step 1: Update Your System

Before installing Docker, update your system packages:

sudo apt update && sudo apt upgrade -y

πŸ”§ Step 2: Install Required Dependencies

Install packages required to use HTTPS repositories:

sudo apt install apt-transport-https ca-certificates curl software-properties-common -y

πŸ” Step 3: Add Docker’s Official GPG Key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor

πŸ“¦ Step 4: Add Docker Repository

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.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 Engine

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

βœ… Step 6: Verify Docker Installation

Run the following command to test Docker:

sudo docker run hello-world

If Docker is installed correctly, you’ll see a confirmation message.

πŸ”“ Step 7: Run Docker Without sudo (Optional)

To run Docker commands without using sudo, add your 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: Install Docker Compose

Docker Compose allows you to define and manage multi-container applications.

sudo apt install docker-compose -y

🌐 Step 9: Run Your First Container

Example: Run Nginx Web Server

docker run -d -p 8080:80 nginx

Now open your browser and visit:

http://<your-server-ip>:8080

You should see the Nginx welcome page.

πŸ§ͺ Example: Run a Test Container

docker run hello-world

πŸ” Basic Security Tips

This verifies that Docker is working correctly.

πŸ’‘ Useful Docker Commands

CommandDescription
docker psList running containers
docker ps -aList all containers
docker imagesList images
docker stop <id>Stop container
docker rm <id>Remove container

🎯 Conclusion

Docker simplifies application deployment by packaging everything into containers. With just a few commands, you can install Docker, run applications, and manage services efficiently.

Whether you’re a developer, system administrator, or learner, Docker is a powerful tool worth mastering.

renjithbs Avatar

Posted by

Leave a comment