Skip to main content

Docker

Docker is an open-sourceapplication container engine,lets developers package apps and dependencies into portable containers。

Installation

Windows/Mac

Download Docker Desktop

Linux (Ubuntu)

Basic Concepts

  • Image: a read-only template containing the filesystem needed to run a container
  • Container: a running instance of an image
  • Repository: a place to store images, such as Docker Hub

Common Commands

Image Management

Container Management

Volume Management

Network Management

Dockerfile

A Dockerfile is a text file used to build an image.

Basic Structure

Common directives

  • FROM: specify the base image
  • WORKDIR: set the working directory
  • COPY: copy files into the image
  • ADD: copy files, with support for URLs and automatic extraction
  • RUN: execute commands during the build
  • CMD: the default command run when the container starts
  • ENTRYPOINT: the entry point, not replaced by normal docker run arguments
  • ENV: set environment variables
  • EXPOSE: declare ports
  • VOLUME: define a data volume
  • USER: specify the runtime user
  • ARG:buildparameters

Multi-stage Build

.dockerignore

This works like .gitignore, excluding files that do not need to be copied into the image.

Image Registry Mirror

Configure image mirrors (Linux)

edit /etc/docker/daemon.json:
Restart Docker:

Practical Tips

Clean System

Auto-restart Containers

Limit Resources

View container IP

Common deployment examples

Nginx

MySQL

Redis

PostgreSQL

References

Last modified on April 17, 2026