Docker
My first week working with Docker! π³
π What is Docker and Why Use It?
- Docker is a platform for building, running, and shipping applications consistently across environments.
- Problems solved by Docker include:
Missing files during deployment. Configuration inconsistency (e.g., environment variables). Version mismatches in dependencies (e.g., different Node.js versions). - Docker packages the application and all dependencies into an isolated container, ensuring the same environment everywhere.
- Containers enable developers to run multiple applications side by side with different dependencies without conflict.
- Docker facilitates easy setup for new team members, and simplifies cleanup by removing containers and dependencies in one go.
π Docker Containers vs Virtual Machines (VMs)
Isolation
- Full OS abstraction using hypervisor in VMs
- Share host OS kernel, isolated process in case of Containers
Operating System
- Each VM needs a full OS
- Containers share host OS kernel
Start-up time
- VMs: Slow (full OS boot)
- Containers: Fast (seconds or less)
Resource usage
- Higher (slice of CPU, memory per VM)
- Lower (share resources dynamically) by docker
Scalability
- Limited (few VMs per physical machine)
- High (dozens or hundreds on one host) for Containers
Therefore,
Containers are more lightweight, quicker to start, and less resource-intensive than VMs.
Containers share the hostβs operating system kernel, e.g., Linux kernel on Linux hosts.
On Windows, Docker can run both Windows and Linux containers due to a custom Linux kernel shipped with Windows 10. On macOS, Docker uses a lightweight Linux VM to run Linux containers because macOSβs kernel differs.
π Docker Architecture
- Docker has a client-server model:
β The Docker client communicates with the Docker engine (server) via RESTful API.
β The Docker engine handles building and running containers. - A container is essentially a special isolated process with its own filesystem as specified by a Docker image.
- Docker images contain:
β A base OS layer (or minimal Linux layer).
β Runtime environments (e.g., Node.js, Python).
β Application files, dependencies, and configuration.
π Installing Docker
- Download and install the latest Docker Desktop (macOS/Windows) or Docker Engine (Linux) from the official [docker.com](https://docs.docker.com/get-docker/).
- Enabling Hyper-V and Containers features on Windows.
- Update the Linux kernel on Windows to avoid installation errors.
- Verify installation by running `docker version` in the terminal, ensuring the Docker engine is running.
π Docker Development Workflow
- Dockerizing an application involves adding a Dockerfile, which contains instructions for building the Docker image.
- A Dockerfile typically:
β Starts from a base image (e.g., `node:alpine`).
β Copies application files into the image.
β Specifies commands to run the app (e.g., `node app.js`). - Build the image using `docker build -t <image-name> .`
- Run containers with `docker run <image-name>`.
- Docker images can be pushed to Docker Hub (a registry akin to GitHub for containers) and pulled on any machine with Docker to ensure consistent environments.
π Key Insights:
- Docker ensures application portability and consistency by packaging all components inside containers.
- Containers are faster, more lightweight, and more resource-efficient than virtual machines.
- Understanding Linux commands and filesystem is essential for effective Docker usage.
- Dockerfiles serve as declarative build scripts that automate environment setup, removing the need for complex deployment instructions.
- Docker Hub simplifies sharing and deploying container images across different environments.
- Linux shell tools and command line proficiency enable easier Docker management and troubleshooting.
π Example Docker Image Information
- Image Name β hello-docker
- Base Image β node:alpine (Linux)
- Size (MB) β 112
- Description β App + Alpine Linux + Node.js 14
π Important Commands:
START β docker compose up -d
STOP β docker compose down
VIEWLOGS β docker logs -f <filename>
UPDATE TO LATEST β docker compose pull && docker compose up -d
RESTART β docker compose restart
CHECK STATUS β docker ps
FULL CLEANUP β docker compose down (removes container, keeps data)
WIPE EVERYTHING β docker compose down -v (includes data)
π LOG example:
βHello from Docker!
Get mridulaβs stories inΒ yourΒ inbox
Join Medium for free to get updates fromΒ thisΒ writer.
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)
3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
- Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/
- For more examples and ideas, visit: https://docs.docker.com/get-started/β

