Operations 11 min read

Master Docker Basics: From Architecture to Hands‑On Dockerfile Build

This article introduces Docker's container technology, explains its architecture and components, demonstrates how to prepare a Docker environment, write and build Dockerfiles, and run containers with common commands, providing practical guidance for developers and operations engineers.

Efficient Ops
Efficient Ops
Efficient Ops
Master Docker Basics: From Architecture to Hands‑On Dockerfile Build

What is Docker?

Docker is a container technology for the software industry.

Before containers, traditional software delivery suffered from:

Slow and error‑prone software updates

Inconsistent environments

High migration costs between environments

Long delivery cycles and high costs

Docker addresses these problems by providing lightweight, fast‑starting containers.

Docker Architecture

Docker follows a client‑server (C/S) model:

Docker Client – the command‑line interface

Docker Server (daemon) – receives client requests and manages containers

Docker Registry – central repository for images (pull/push)

Note: An image becomes a container when run with docker run .

Container startup is fast because:

Images use layered filesystems, keeping disk usage low

Containers share the host kernel, reducing memory consumption

Preparing for Docker Hands‑On

Four steps are required:

Log in to OSChina Git

Fork the docker-training repository

Connect to a server via SSH

Clone the forked repository to the server

What is a Dockerfile?

A Dockerfile is a script that defines how to build a Docker image; its syntax resembles Linux shell commands.

Typical Dockerfile sections:

Base image information

Maintainer information

Image build commands (RUN, ADD, COPY, etc.)

Container start command (CMD, ENTRYPOINT)

Key Dockerfile instructions demonstrated:

# MAINTAINER Carson, C.J. Zeong <[email protected]>
FROM centos:centos7.1.1503
ENV TZ "Asia/Shanghai"
ADD aliyun-mirror.repo /etc/yum.repos.d/CentOS-Base.repo
RUN yum install -y curl wget tar bzip2 unzip vim-enhanced ...
RUN pip install supervisor
ADD supervisord.conf /etc/supervisord.conf
EXPOSE 22
ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]

Explanation of selected instructions: ADD copies files or URLs into the image and can unpack archives. COPY copies local files into the image. RUN executes shell commands, creating a new image layer each time. ENV sets environment variables (e.g., timezone). EXPOSE declares a port (e.g., 22) for mapping. ENTRYPOINT defines the process that runs when the container starts.

Building and Running Images

Build an image with: docker build -t csphere/centos:7.1 . Image naming follows registry/namespace/image:tag (default tag is latest).

Run a container from the image:

docker run -d -p 2222:22 --name base csphere/centos:7.1

Common run options: -d – run in background -it – interactive foreground -p hostPort:containerPort – fixed port mapping -P – random host port mapping for exposed ports --name – assign a name to the container

Inspect containers with docker ps (running) or docker ps -a (all).

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.

OperationsDevOpsDockerfile
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

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.