Docker Questions and Answers

 

1️⃣ What is the difference between Docker Image and Container?

  • Image → Immutable blueprint

  • Container → Running instance of image

  • Images are read-only layers

  • Containers add writable layer

2️⃣ What are Docker Layers?

Each instruction in a Dockerfile creates a layer.

Example:

FROM python:3.12
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .

Each step = new layer → cached for faster builds.

3️⃣ What is Union File System?

Docker uses layered filesystem (AUFS/OverlayFS).

It allows:

  • Sharing common layers

  • Saving storage

  • Faster image pulls

5️⃣ What is Docker Networking?

Types:

  • bridge (default)

  • host

  • none

  • overlay (Swarm)

  • macvlan

Containers communicate via service names in Docker Compose.

6️⃣ How does Docker handle storage?

Using:

  • Volumes

  • Bind mounts

  • tmpfs mounts

Volumes are preferred for production.

7️⃣ How to reduce Docker image size?

  • Use slim images

  • Multi-stage builds

  • Remove cache files

  • Use .dockerignore

  • Combine RUN commands

8️⃣ What happens when you run docker run?

  1. Pull image (if not available)

  2. Create container

  3. Allocate filesystem

  4. Configure networking

  5. Start process

9️⃣ Difference between Docker Compose and Kubernetes?

Docker Compose            Kubernetes
Local dev                Production orchestration
Single host                Multi-node cluster
Simple YAML                Complex control plane

🔟 Explain Docker Swarm

Docker Swarm is Docker’s native clustering solution.

Features:

  • Load balancing

  • Service scaling

  • Rolling updates

Comments

Popular posts from this blog

Database Integration in FastAPI (SQLAlchemy CRUD)

Middleware & CORS in FastAPI

Python Data Handling