π DevOps Roadmap 2025 β Step 4: Mastering Docker (Part 1 β Beginner to Intermediate Guide)

This is Part 1 of our Docker Blog Series. In upcoming parts, weβll explore Docker Images, Networking, Compose, and more.
π³ Introduction to Docker
Docker is an open-source platform that enables developers and DevOps engineers to build, package, and run applications inside containers.
Containers are lightweight, portable, and consistent environments that ensure your application works the same way on your local machine, in testing, and in production.
πΉ Why Docker is Important in DevOps
Before Docker, developers faced the "it works on my machine" problem.
Applications behaved differently on production servers because of mismatched dependencies.
Docker helps by:
Consistency β Same environment for development, testing, and production.
Portability β Runs anywhere: laptop, server, or cloud.
Scalability β Works with orchestration tools like Kubernetes.
Faster Deployment β Pre-built images can spin up in seconds.
Isolation β Each container runs independently without affecting others.
π Docker vs Virtual Machines (VMs)
Feature | Docker Containers | Virtual Machines |
OS | Share host OS kernel | Separate OS for each VM |
Size | MBs (small) | GBs (large) |
Speed | Starts in seconds | Starts in minutes |
Performance | Near native speed | Slower due to hypervisor |
Portability | High | Moderate |
Use Case | Microservices, CI/CD | Full OS environments |
π‘ Simple analogy:
VMs are like renting separate houses, each with its own utilities.
Docker containers are like separate rooms in the same house β isolated but sharing some facilities.
βοΈ Installing Docker (Local Machine)
1. Install Docker on Windows
Download Docker Desktop from https://www.docker.com/products/docker-desktop/
Install and start Docker Desktop.
Verify installation:
docker --version
2. Install Docker on Ubuntu/Linux
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce
Verify:
docker --version
π How Docker Works (Architecture)
Docker follows a client-server architecture:
Docker Client β The command-line tool (
docker
) you use to interact with Docker.Docker Daemon β The background process that builds, runs, and manages containers.
Docker Images β Read-only templates for creating containers.
Docker Containers β Running instances of Docker images.
Docker Registry β Stores and shares Docker images (e.g., Docker Hub, Azure Container Registry).
π Common Docker Commands (Part 1 β More than 30+)
Basic Commands
docker --version # Check Docker version
docker info # Get system-wide info
docker help # Get help for commands
Image Commands
docker pull nginx # Download image from Docker Hub
docker images # List downloaded images
docker rmi nginx # Remove image
docker build -t myapp . # Build image from Dockerfile
docker tag myapp myrepo/myapp:v1 # Tag image
Container Commands
docker run hello-world # Run a test container
docker run -it ubuntu bash # Start container interactively
docker run -d -p 8080:80 nginx # Run in background with port mapping
docker ps # List running containers
docker ps -a # List all containers
docker stop container_id # Stop container
docker start container_id # Start container
docker restart container_id # Restart container
docker rm container_id # Remove container
Advanced Commands
docker exec -it container_id bash # Access running container shell
docker logs container_id # View container logs
docker cp file.txt container_id:/ # Copy file into container
docker commit container_id myimage # Create image from container
docker network ls # List networks
docker volume ls # List volumes
docker system prune # Remove unused data
π‘ Example: Running an Nginx Web Server
docker pull nginx
docker run -d -p 8080:80 nginx
Now, visit http://localhost:8080
in your browser to see the Nginx welcome page.
β Common Docker Interview Questions (Part 1)
What is Docker?
Docker is a containerization platform that packages applications and dependencies into portable containers.What is the difference between Docker and a Virtual Machine?
Docker shares the host OS kernel, making it lightweight and faster; VMs have separate OS instances.What is a Docker Image?
A read-only template used to create containers.What is a Docker Container?
A running instance of a Docker image.What is the purpose of a Dockerfile?
Itβs a script with instructions to build a Docker image.What is Docker Hub?
A public registry for Docker images.How do you see running Docker containers?
docker ps
How do you stop and remove a container?
docker stop <id>
anddocker rm <id>
What is the difference between
COPY
andADD
in Dockerfile?
COPY
copies files only;ADD
can copy and extract archives or download from URLs.How do you persist data in Docker?
By using Docker volumes.Can we run multiple processes in a single container?
Yes, but best practice is one process per container.How do you check container logs?
docker logs <container_id>
What is the difference between
docker run
anddocker start
?docker run
creates and starts a new container;docker start
restarts an existing stopped container.What is the purpose of
-p
in Docker run?
It maps host ports to container ports.How do you remove all stopped containers?
docker container prune
π¬ Next in Part 2:
We will cover Dockerfile in detail, multi-stage builds, Docker networking, Docker Compose, and more advanced interview questions.
Subscribe to my newsletter
Read articles from Harshal Sonar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
