DOCKER
Docker is a platform that packages applications and their dependencies into lightweight containers, ensuring they run consistently across different environments.
HOW IT WORKS
Instead of the familiar problem of “it works on my machine,” Docker guarantees “it works everywhere.” With Docker, developers don’t need to manually install dependencies or replicate complex setups. As long as Docker is installed, they can run containers that already include the code, versions, dependencies and everything an application requires to run.
Docker manages these containers
Containers vs Virtual Machines (VM)
Each VM runs its own OS along with the application and its dependencies hence making them larger and slower to start
Containers share host OS kernel while isolating processes. Each container has only the application and its dependencies, not a full OS hence faster startup
IMAGE
A Docker image is a blueprint or template for creating containers. It packages everything an application needs to run.
It has the following stored inside it:
- Runtime environment(e.g., specific python or java version)
- Required libraries and dependencies
- The application code
- Base OS (e.g., Ubuntu, Alpine, Debian)
- Docker images are read-only and immutable—once built, they do not change
CONTAINER
A container is a runnable instance of an image ie when you run an image, Docker creates a container from it. Each container is an isolated process that executes the application exactly as outlined/ defined in the image it is in.
DOCKER FILE
A recipe/instruction file used to build a Docker image.
Contains steps like:
** What base image to use
** What libraries to install
** How to copy code into the image
** What command to run when the container starts
DOCKER HUB
A registry/repository where Docker images are stored and shared.
Its like GitHub but for images. Official images (Python, Postgres, Nginx, Ubuntu, etc.) live here. You can also push your custom images for sharing/deployment.
To install Docker on WSL 2 with Ubuntu 22.04 follow these steps:
Step 1: Update system
sudo apt update && sudo apt upgrade -y
Step 2: Install required dependencies
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
Step 3: Add Docker GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Step 4: Add Docker Repository
echo "deb [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
Step 5: Install Docker image
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 6: Add your user to the Docker Group
sudo usermod -aG docker $USER
Step 7: Finally restart WSL on CMD/ Powershell.
wsl --shutdown
then
docker version
You should see something like below
Docker version 28.3.3, build 980b856
DOCKER COMPOSE
Docker Compose is a tool that allows you to define, configure, and run multi-container Docker applications using a single YAML file (docker-compose.yml).
Instead of starting each container manually with long docker run commands, Compose lets you describe the whole application stack in one place and bring it up with:
docker compose up
HOW IT WORKS
With Docker Compose, you use a special configuration file written in YAML (called docker-compose.yml or compose.yaml) to describe your application. In this file, you list all the services your app needs like a web server, database, or cache and how they should work together.
Once the file is ready, you can start everything with a single command using the Compose CLI
docker compose up
The format of the Compose file follows a standard set of rules called the Compose Specification, which ensures your multi-container applications are defined in a consistent way.
WHY USE COMPOSE
- It simplifies multi-container app setup: Defines and manages multi-container apps in one YAML file
- Efficient collaboration: Shareable YAML files support smooth collaboration between developers and operations
- Makes environments reproducible with a single command.
- Great for local development, CI/CD pipelines, and testing microservices
To install Docker compose, follow steps defined in below link
https://docs.docker.com/compose/install/
COMMANDS
- To start all the services defined in your compose.yaml file run
docker compose up
- To stop the services run
docker compose down
- To list all the services and their current status run
docker compose ps
Top comments (0)