๐Ÿ“˜ Docker Summary Guide

 ๐Ÿ“˜ Docker Summary Guide


I. What is Docker?

Docker is a platform for developing, shipping, and running applications in lightweight, portable containers. Containers package code and dependencies together so applications run reliably across different environments.


II. Core Concepts

  1. Image
    A lightweight, standalone, immutable file that includes the application and all its dependencies.

  2. Container
    A runnable instance of an image. Containers are isolated from the host and each other.

  3. Dockerfile
    A script used to build Docker images. It contains instructions (like FROM, RUN, COPY, etc.).

  4. Docker Engine
    The core client-server application:

    • Docker Daemon (dockerd): Runs in the background.

    • Docker CLI (docker): Command-line interface to interact with Docker.

  5. Docker Hub / Registry
    Central repositories where Docker images are stored and shared.

    • Docker Hub is the default public registry.


III. Docker Architecture



  1. Docker Client
    The user interface to Docker. Sends commands to the daemon (via REST API).

  2. Docker Daemon
    Manages Docker objects (images, containers, networks, volumes). Listens on a socket.

  3. Docker Objects

    • Images

    • Containers

    • Networks

    • Volumes


IV. Dockerfile Instructions (Key Commands)

Instruction Description
FROM Base image to start with.
RUN Executes command during image build.
COPY / ADD Copy files into the image.
CMD Default command when a container runs.
ENTRYPOINT Sets the main executable.
EXPOSE Documents port(s) the container listens on.
ENV Sets environment variables.
WORKDIR Sets the working directory inside the container.

V. Container Lifecycle


  1. Create
    Using docker create or docker run.

  2. Start / Stop
    Use docker start / docker stop.

  3. Pause / Unpause
    Temporarily suspend or resume.

  4. Restart / Remove
    Manage lifecycle and cleanup.


VI. Docker Networking

  1. Bridge Network (default)
    Containers get an IP on a private network; NAT used for external access.

  2. Host Network
    Container shares the host network.

  3. Overlay Network
    Used in Docker Swarm for multi-host communication.

  4. None
    No network access for the container.


VII. Docker Storage

  1. Volumes

    • Managed by Docker. Persistent storage.

    • Shared between containers.

  2. Bind Mounts

    • Mount a file/folder from the host into the container.

  3. tmpfs Mounts

    • Temporary filesystems stored in memory.


VIII. Docker Compose

Docker Compose is a tool to define and run multi-container applications using a docker-compose.yml file.

  • Define services, networks, volumes.

  • Use docker-compose up to start everything.

  • Ideal for local development and testing environments.


IX. Docker Swarm (Optional: Native Orchestration)

Docker Swarm is Docker's built-in container orchestration tool.

  • Turns multiple Docker engines into a single cluster.

  • Manages container deployment, scaling, load-balancing.

  • Use docker swarm init to start a swarm.


X. Docker Best Practices

  1. Keep images small using minimal base images (alpine).

  2. Use .dockerignore to exclude files from builds.

  3. Minimize layers in Dockerfile.

  4. Avoid running containers as root inside.

  5. Use multistage builds for cleaner production images.



Comments

Popular posts from this blog

SAVE TAX ๐Ÿ’ต

LIFE A JOURNEY

๐ŸฆŸ The Truth About Mosquitoes: More Than Just an Itchy Bite