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.
- 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.
Leave a comment