Architecture & commands
Docker was initially developed for Linux, but later, Docker Desktop was introduced, allowing Linux-based containers to run on Windows and macOS.
Docker Desktop uses a hypervisor layer with a Linux distribution on top of it.
🖥️ What is a Hypervisor?
A hypervisor is software that allows multiple virtual machines (VMs) to run on a single physical host by abstracting hardware resources.
It sits between the hardware and the VMs, managing resources and ensuring independent operation.
⚙️ Docker Architecture and its Components
When Docker is installed, the Docker engine gets installed, consisting of three main parts:
- 🔹 Server: Pulls images, manages images and containers.
- 🔹 API: Interacts with the Docker server.
- 🔹 CLI: Command Line Interface to execute Docker commands.
🔧 Server Components
- 🔹 Container Runtime: Manages container execution.
- 🔹 Volumes: Enables data persistence.
- 🔹 Networking: Configures communication between containers.
- 🔹 Build Images: Creates custom Docker images.
🚀 Essential Docker Commands
Command | Description |
---|---|
docker run --name mypg -e POSTGRES_PASSWORD=mypass -d postgres:13.16 |
Creates a container from an image. |
docker start imageID |
Starts a stopped container. |
docker stop imageID |
Stops a running container. |
docker images |
Lists all locally stored Docker images. |
docker ps |
Lists running containers. |
docker ps -a |
Shows all running and exited containers. |
docker logs imageID |
Fetches logs of a container’s history. |
docker exec -it image-ID /bin/bash |
Creates a new bash session inside the container. |
docker rmi image-ID |
Removes an image. |
docker scout cves image-ID |
Checks for Common Vulnerabilities and Exposures (CVEs) in a Docker image. |
docker pull registryDomain/image |
Pulls an image from the repository. |
docker pull mongo |
Equivalent to docker pull docker.io/library/mongo . |
🎯 Best Practices for Using Docker
- ✅ Use official images from Docker Hub for better security.
- ✅ Always define a tag when pulling images to avoid unwanted updates.
- ✅ Regularly check for vulnerabilities using
docker scout cves
. - ✅ Use volumes for persistent storage instead of saving data inside containers.
📌 Conclusion
Docker Desktop provides an efficient way to manage containers across different operating systems.
Understanding Docker architecture, commands, and best practices will help in deploying and managing applications effectively.