Software-Engineering

Docker & Docker Compose

What is Docker?

Docker is a containerization platform that allows developers to package an application along with its dependencies, configuration, and runtime into a single unit called a container, which can run consistently across different systems.

Docker solves the common problem of:

“It works on my machine, but not on another system or server.”


Why Docker is Needed

In real-world projects:

Docker solves this by:

Key Benefits


What is a Container?

A container is an isolated running process created from a Docker image.

It includes:

Containers are:


Core Docker Concepts

Docker Image

A Docker image is a read-only blueprint used to create containers.

Image → Container


Dockerfile

A Dockerfile defines how an image is built.

It contains steps such as:


Volumes (Persistent Storage)

By default, containers have temporary storage.

Volumes are used to:

Volumes are not deleted when containers are removed.


Docker Networking

Docker provides a virtual network inside the host machine.


Docker Workflow

  1. Write application code
  2. Create a Dockerfile
  3. Build a Docker image
  4. Run a container from the image
Code → Image → Container

What is Docker Compose?

Docker Compose is a tool used to define and manage multi-container applications using a single YAML configuration file (docker-compose.yml).

It is mainly used when an application requires:

All running together.


Why Docker Compose is Needed

Without Docker Compose:

Docker Compose solves this by:


docker-compose.yml (Concept)

A Compose file defines:

Each service represents one container.


Docker vs Docker Compose

Feature Docker Docker Compose
Single container Yes Yes
Multi-container setup Difficult Easy
Configuration CLI + Dockerfile YAML file
Best use case Single service, CI/CD Local dev, microservices

Common Use Cases

Docker

Docker Compose


Best Practices