🚀 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 -o /usr/share/keyrings/docker.gpg
 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&gt;:8080
You should see the Nginx welcome page.
離 Example: Run a Test Container
docker run hello-world
This verifies that Docker is working correctly.
 Basic Security Tips
Avoid exposing Docker services directly to the internet without proper security controls
Keep your system updated regularly
Use official images from trusted sources
Limit container privileges when possible
 Useful Docker Commands
Command
Description
docker ps
List running containers
docker ps -a
List all containers
docker images
List 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.
Happy containerizing! 

renjithbs Avatar

Posted by

Leave a comment