Operations 12 min read

Why Docker? A Practical Guide to Containerizing Development Environments

This article explains why Docker solves traditional development environment problems by offering lightweight, fast-start containers, automated image builds with Dockerfiles, and orchestration via Docker Compose, while also covering basic commands, best practices, and its role in CI/CD and cloud-native workflows.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Why Docker? A Practical Guide to Containerizing Development Environments

Why Docker?

Traditional web projects often depend on many services such as PHP, MySQL, Redis, and Node, leading to version conflicts, shared configuration issues, and manual deployment overhead. Virtual machines address some problems but introduce large image sizes, slow boot times, and lack automation.

Docker provides a process‑level virtualization solution with several advantages:

Small image size because the host OS is not packaged.

Fast startup with low resource consumption.

Sandbox isolation between services.

Dockerfile‑based automated image building.

Docker Hub for easy image sharing.

Unlike VMs, Docker containers share the host kernel, making them lightweight and portable.

Docker Basics

Docker runs on Windows, Linux, macOS, AWS, and Azure (Windows requires Win10+, macOS requires EI Captain+). It follows a client‑server architecture.

Key concepts: Dockerfile, Image, Container, Repository. An image is built from a Dockerfile and can be pushed to Docker Hub. A container is an instance of an image. $ docker run [organization/]<image_name>[:tag] If the organization is omitted, library is used; if the tag is omitted, latest is assumed. Running the official hello-world image demonstrates automatic image pulling from Docker Hub.

Note: Containers are stateless; store persistent data using volumes or external storage.

Dockerfile

A Dockerfile defines how to build an image. Benefits include version‑controlled, text‑based builds and layer reuse.

Use # for comments. FROM specifies the base image. RUN executes commands during image build (e.g., installing packages). COPY copies files into the image. WORKDIR sets the working directory. CMD or ENTRYPOINT defines the container’s start command (only one can be present).

Example Dockerfile for a Node application:

FROM mhart/alpine-node:8.9
LABEL maintainer="lizheming <[email protected]>"
LABEL org.label-schema.name="Drone Wechat Notification"
LABEL org.label-schema.vendor="lizheming"
LABEL org.label-schema.version="1.1.0"
WORKDIR /wechat
COPY package.json /wechat/package.json
RUN npm install --production --registry=https://registry.npm.taobao.org
COPY index.js /wechat/index.js
ENTRYPOINT ["node", "/wechat/index.js"]

Build the image with:

$ docker build lizheming/drone-wechat:latest

Docker Compose

When a project requires multiple services, Docker Compose orchestrates them using a YAML file, eliminating the need to run many separate docker run commands.

Install with pip install docker-compose, then use docker-compose up and docker-compose stop to manage the stack.

version: "2"
services:
  nginx:
    depends_on:
      - php
    image: "nginx:latest"
    volumes:
      - "$PWD/src/docker/conf:/etc/nginx/conf.d"
      - "$PWD:/home/q/system/m_look_360_cn"
    ports:
      - "8082:80"
    container_name: "m.look.360.cn-nginx"
  php:
    image: "lizheming/php-fpm-yaf"
    volumes:
      - "$PWD:/home/q/system/m_look_360_cn"
    container_name: "m.look.360.cn-php"

Compose automatically resolves container dependencies and provides service name DNS resolution, allowing Nginx to reach the PHP container via php:9000.

Docker‑Related Benefits

Beyond simplifying environment setup, Docker enables CI/CD pipelines, integrates with Kubernetes or Docker Swarm for elastic scaling, and reduces operational overhead.

Learning Resources

What is Docker? https://cloud.tencent.com/developer/article/1005172

Docker from Beginner to Practice https://yeasy.gitbooks.io/docker_practice/

Docker Compose Detailed Guide https://www.jianshu.com/p/2217cfed29d7

Deep Dive into Docker https://www.kancloud.cn/infoq/docker/79768

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Dockerci/cdDevOpscontainerizationDockerfileDocker Compose
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.