When I started learning Docker, I quickly realized that understanding a few core concepts and commands makes working with containers much easier. Instead of memorizing commands, I wanted to understand what Docker does and why each command is useful.
In this article, I’m sharing my beginner notes. If you’re just getting started with Docker, this guide should help you build a solid foundation.
What is Docker?
Docker is a containerization platform that allows you to package an application together with all of its dependencies. This ensures the application runs consistently across different environmentsโwhether it’s your local machine, a testing server, or production.
One of Docker’s biggest advantages is the famous phrase:
“It works on my machine.” โ With Docker, it works on every machine.
Docker Architecture
Before learning the commands, it’s helpful to understand how Docker works behind the scenes.
Docker Client
The Docker Client is the command-line interface (CLI) that we use every day.
Whenever we run commands like:
docker run
docker ps
docker pull
Enter fullscreen mode Exit fullscreen mode
the Docker Client sends those requests to the Docker Daemon.
Docker Daemon
The Docker Daemon (dockerd) runs in the background.
It is responsible for:
- Building images
- Running containers
- Managing images
- Managing networks
- Managing volumes
Think of it as the engine that powers Docker.
Docker Image
A Docker Image is a read-only template that contains everything required to run an application:
- Application code
- Runtime
- Libraries
- Dependencies
- Configuration
Images are used to create containers.
Docker Container
A Container is a running instance of a Docker image.
Containers are:
- Lightweight
- Isolated
- Portable
- Fast to start
You can create multiple containers from the same image.
Docker Registry
A Docker Registry is where Docker images are stored and shared.
The most commonly used public registry is Docker Hub, where thousands of official and community images are available.
What is Containerization?
Containerization means packaging an application together with all of its dependencies so that it runs the same way everywhere.
Instead of worrying about different operating systems or missing libraries, Docker provides a consistent environment.
Essential Docker Commands
1. Check Docker Installation
Check Docker Version
docker -v
Enter fullscreen mode Exit fullscreen mode
Displays the installed Docker version.
Show Docker Client & Daemon Version
docker version
Enter fullscreen mode Exit fullscreen mode
Shows both the Docker Client and Docker Daemon versions.
Display Docker Information
docker info
Enter fullscreen mode Exit fullscreen mode
Displays detailed information about your Docker installation.
2. Working with Images
Download an Image
docker pull hello-world:latest
Enter fullscreen mode Exit fullscreen mode
Downloads the image from Docker Hub.
Note: If the image already exists locally, Docker won’t download it again.
View Local Images
docker images
Enter fullscreen mode Exit fullscreen mode
or
docker image ls
Enter fullscreen mode Exit fullscreen mode
Lists all images stored locally.
Remove an Image
docker image rm <image_name_or_id>
Enter fullscreen mode Exit fullscreen mode
or
docker rmi <image_name_or_id>
Enter fullscreen mode Exit fullscreen mode
Deletes an image from your local machine.
3. Creating and Running Containers
Create a Container
docker create ubuntu
Enter fullscreen mode Exit fullscreen mode
Creates a container but does not start it.
Start an Existing Container
docker start <container_id>
Enter fullscreen mode Exit fullscreen mode
Starts a previously created container.
Create and Run a Container
docker run hello-world
Enter fullscreen mode Exit fullscreen mode
If the image doesn’t exist locally, Docker downloads it first and then creates and starts the container.
Run an Interactive Ubuntu Container
docker run -it ubuntu
Enter fullscreen mode Exit fullscreen mode
Downloads the Ubuntu image (if needed), starts the container, and opens an interactive terminal where you can execute Linux commands.
Run a Container in Detached Mode
docker run -d nginx
Enter fullscreen mode Exit fullscreen mode
Runs the container in the background.
4. Managing Containers
View Running Containers
docker ps
Enter fullscreen mode Exit fullscreen mode
Lists only running containers.
View All Containers
docker ps -a
Enter fullscreen mode Exit fullscreen mode
Lists both running and stopped containers.
Stop a Container
docker stop <container_id>
Enter fullscreen mode Exit fullscreen mode
Stops a running container.
Restart a Container
docker restart <container_id>
Enter fullscreen mode Exit fullscreen mode
Restarts a container.
Remove a Container
docker rm <container_id>
Enter fullscreen mode Exit fullscreen mode
Deletes a stopped container.
5. Execute Commands Inside a Running Container
Open a Bash shell inside a running container:
docker exec -it <container_id> bash
Enter fullscreen mode Exit fullscreen mode
For example, if you’re running Redis:
docker exec -it <container_id> redis-cli
Enter fullscreen mode Exit fullscreen mode
6. Viewing Logs
Display Container Logs
docker logs <container_id>
Enter fullscreen mode Exit fullscreen mode
Shows logs generated by the container.
Follow Logs in Real Time
docker logs -f <container_id>
Enter fullscreen mode Exit fullscreen mode
Streams logs as they are generated.
7. Cleaning Up Docker Resources
Remove Unused Resources
docker system prune
Enter fullscreen mode Exit fullscreen mode
This removes:
- Stopped containers
- Unused networks
- Dangling images
- Build cache
Remove All Unused Images
docker system prune -a
Enter fullscreen mode Exit fullscreen mode
Removes all unused images, stopped containers, unused networks, and build cache.
Quick Summary
Command Purposedocker -v
Check Docker version
docker version
Show Docker Client & Daemon version
docker info
Display Docker information
docker pull
Download an image
docker images
List local images
docker run
Create and run a container
docker create
Create a container
docker start
Start an existing container
docker ps
List running containers
docker ps -a
List all containers
docker exec -it
Execute commands inside a running container
docker logs
View container logs
docker image rm
Remove an image
docker rm
Remove a container
docker system prune
Clean up unused Docker resources
Final Thoughts
Docker is one of the most important tools in modern software development and DevOps. While there are many advanced topics to exploreโsuch as Dockerfiles, Docker Compose, volumes, networking, Kubernetes, and container orchestrationโmastering these fundamentals will make your learning journey much smoother.
I’m currently learning Docker as part of my DevOps roadmap, and I’ll continue sharing practical notes and examples as I progress.
If you have suggestions, best practices, or beginner tips, feel free to share them in the comments.
Happy Learning!
๋ต๊ธ ๋จ๊ธฐ๊ธฐ