What is Docker? Docker Container: A Deep Dive into Docker
Docker is an open-source platform that automates the deployment of applications inside lightweight, portable units called containers. A container packages an application's code together with everything it needs to run — libraries, dependencies, environment variables, and configuration files — so it behaves the same way regardless of where it's deployed.
Images vs Containers
Two terms are central to understanding Docker:
- Docker Image: A read-only template that defines what goes into a container — the base operating system layer, application code, dependencies, and startup instructions. Images are built from a
Dockerfile. - Docker Container: A running instance of an image. You can start, stop, move, or delete a container, and you can create many containers from the same image.
How Docker Containers Work
Docker containers rely on operating system-level virtualization features built into the Linux kernel:
- Namespaces: Isolate a container's view of the system — process IDs, network interfaces, mount points, and hostnames — so it appears to have its own environment.
- Control Groups (cgroups): Limit and account for a container's use of CPU, memory, disk I/O, and network resources.
- Union File Systems: Allow images to be built in layers, where each instruction in a Dockerfile creates a new layer. Layers are cached and reused, making builds and image transfers efficient.
The Docker Architecture
| Component | Role |
|---|---|
| Docker Client | The CLI (docker) or GUI tool used to issue commands. |
| Docker Daemon (dockerd) | Background service that builds, runs, and manages containers and images. |
| Docker Images | Read-only templates used to create containers. |
| Docker Containers | Running instances of images. |
| Docker Registry | Storage for images, such as Docker Hub or a private registry. |
A Simple Dockerfile Example
Here's a minimal Dockerfile for a Node.js application, showing how an image is defined layer by layer:
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
Container vs Virtual Machine
| Aspect | Virtual Machine | Docker Container |
|---|---|---|
| OS | Full guest OS per VM | Shares host OS kernel |
| Size | Gigabytes | Megabytes |
| Boot Time | Minutes | Milliseconds to seconds |
| Isolation | Strong (hardware-level) | Process-level (namespaces/cgroups) |
| Density | Fewer per host | Many more per host |
Ready to master Docker?
Build, ship, and run containerized applications with confidence. Learn Docker and Kubernetes from industry experts with hands-on projects.