
Docker is one of the most widely used tools in DevOps. It is an open-source containerization platform that helps you build, package, and run applications consistently across all environments.
Docker allows you to run the same application on development, testing, and production servers without dependency or configuration issues.
In this Docker tutorial for beginners, you will learn all the basic concepts with simple explanations and easy-to-practice examples.
In This Tutorial, You Will Learn
- What is Docker?
- Why Docker is widely used in DevOps
- Difference between Docker and Virtual Machines
- How to install Docker on Linux, Windows, and Mac
What Is Docker?
Docker is a tool that helps you package your application along with its libraries and dependencies into a single unit called a container. This container can run on any system where Docker is installed.
Docker Image
A Docker image is a read-only template or blueprint used to create containers. It is built using a file called a Dockerfile, which contains step-by-step instructions to build the image.
Docker Container
A Docker container is a lightweight, standalone, and executable unit created from a Docker image. It contains the application code, libraries, and dependencies required to run the application.
Docker Hub
Docker Hub is the default cloud registry used to store Docker images. You can store images as public or private.
Other popular container registries include:
- Amazon ECR (Elastic Container Registry)
- Azure ACR (Azure Container Registry)
- Google GCR (Google Container Registry)
Docker Host
A Docker host is the system where the Docker Engine is installed and running. This can be your local machine or a server.
Docker Daemon
The Docker daemon is a background service that manages Docker images, containers, volumes, and networks.
Why Docker Is Used in DevOps
- Consistency: Runs the same across development, testing, and production environments.
- Faster Deployment: Containers start in seconds.
- Efficiency: Containers are lightweight and use fewer system resources.
- Easy Scaling: You can scale applications by running more containers.
Docker vs Virtual Machines
| Feature | Docker Containers | Virtual Machines |
|---|---|---|
| Startup Time | Seconds | Minutes |
| Size | Very small (MBs) | Very large (GBs) |
| Operating System | Shares host OS | Has full OS |
| Performance | Near native | Slower |
| Resource Usage | Lightweight | Heavy |
How to Install Docker on Ubuntu (Linux)
sudo apt update sudo apt install docker.io -y
Start and Enable Docker
sudo systemctl start docker sudo systemctl enable docker
Verify Installation
docker --version
Sample Output:
Docker version 24.0.2, build cb74dfc
Add Your User to the Docker Group
sudo usermod -aG docker $USER
Log out and log in again to apply the changes.
Docker Installation on Windows and Mac
For Windows and Mac, Docker provides Docker Desktop.
- Go to the official Docker website
- Download Docker Desktop
- Install and start Docker
Basic Docker Commands
The following table lists the most important Docker commands that every beginner should know, along with their purpose.
| Command | Description |
|---|---|
docker --version | Displays the installed Docker version. |
docker images | Lists all Docker images available on your system. |
docker ps | Shows only the currently running containers. |
docker ps -a | Shows all containers, including stopped ones. |
docker run hello-world | Runs a test container to verify that Docker is working correctly. |
docker run -it ubuntu bash | Starts an interactive Ubuntu container and opens a shell inside it. |
docker stop <container_id> | Stops a running container using its container ID. |
docker rm <container_id> | Removes a stopped container from the system. |
docker rmi <image_id> | Deletes a Docker image from the local system. |
docker info | Displays detailed information about the Docker system and configuration. |
docker pull nginx | Downloads the Nginx image from Docker Hub to your local machine. |
docker attach <container_id> | Attaches your terminal to a running container to view its output. |
docker ps -q -f "state=exited" | Lists only the container IDs of containers that have exited. |
docker stop $(docker ps -a -q) | Stops all running and stopped containers at once. |
docker rm <container_name> | Removes a container using its container name. |
Conclusion
Docker is a core tool in modern DevOps. By learning these basic and advanced commands, you build a strong foundation for container orchestration tools like Kubernetes and for building CI/CD pipelines.
In the next tutorial, you can learn how to write your first Dockerfile and create a real Dockerized application step by step.
Leave a Reply