Master Docker: From Basics to Advanced Container Management
This comprehensive Docker guide covers its origins, core concepts such as images, containers, and registries, installation steps, essential commands, building custom images, managing containers, and best practices for deployment, providing hands‑on examples and tips for both beginners and seasoned developers.
0 Quick Start
Docker began as an internal hobby project at dotCloud.
Docker is written in Go.
The goal is a lightweight OS‑level virtualization solution.
It builds on Linux containers (LXC) and related technologies.
Containers start in seconds, far faster than traditional VMs.
Docker achieves high resource utilization; thousands of containers can run on a single host.
The following images compare Docker with traditional virtualization, showing that containers virtualize at the OS layer while VMs virtualize at the hardware layer.
1 Installation
The official website provides installation guides for Mac, Linux, and Windows; follow the official documentation.
Kitematic is a graphical tool (Visual Docker Container Management on Mac & Windows) that helps users explore Docker.
Daemon
When running the Docker daemon you can change the binding interface with the -H flag, e.g.: sudo /usr/bin/docker -d -H tcp://0.0.0.0:2375 To avoid typing the long command each time, set the environment variable:
export DOCKER_HOST="tcp://0.0.0.0:2375"Graphical User Interface
Common web management interfaces include:
Shipyard
Portainer
2 Basic Concepts
Image
A read‑only template used to create Docker containers.
Based on a Union file system with layered structure.
Can be created, updated, or downloaded from others; it is the "source code" of a container.
Container
A running instance created from an image, with a writable top layer.
Can be started, stopped, or deleted; each container is isolated for security.
Essentially a lightweight Linux environment (including root privileges, process, user, and network spaces) plus the application.
Registry
A centralized place to store image files, public or private.
The largest public registry is Docker Hub.
Chinese public registries include Docker Pool.
After creating an image, use docker push to upload it; others can docker pull it.
The registry concept is similar to Git hosting services.
Docker uses a client/server architecture; the client sends requests to the Docker daemon.
3 Common Commands
Check Docker status: sudo docker info List running containers: docker ps (add -a to show all, -l for the latest).
A Simple Example
Run a basic container to print a message:
docker run ubuntu:14.04 /bin/echo 'Hello wdx!'Start an interactive bash session: docker run -t -i ubuntu:14.04 /bin/bash The -t flag allocates a pseudo‑TTY; -i keeps STDIN open.
4 Container Overview
A container runs one or a group of applications with its own runtime environment, unlike a full VM that simulates an entire OS.
Containers can be created from an image or restarted from a stopped state; they are lightweight enough that users often delete and recreate them.
5 Running Containers
When creating a container with docker run, Docker performs:
Check for the image locally; pull from a public registry if missing.
Create and start a container from the image.
Mount a writable layer on top of the read‑only image.
Bridge a virtual network interface from the host to the container.
Assign an IP address from the host's address pool.
Execute the user‑specified application.
Terminate the container when the process exits.
Restart a stopped container with docker start.
6 Images
Pull an image from a registry: sudo docker pull ubuntu:12.04 Or from a custom registry: sudo docker pull dl.dockerpool.com:5000/ubuntu:12.04 List local images with docker images.
7 Running Images
Search Docker Hub for the whalesay image and run it:
docker run docker/whalesay cowsay boo
The command cowsay runs inside the container with argument boo.
8 Building Images
Create a Dockerfile in a new directory:
mkdir wdxtub; cd wdxtub
gedit Dockerfile
Add FROM docker/whalesay:latest as the base image.
Add commands, e.g., RUN apt-get -y update && apt-get install -y fortunes.
Specify the default command with CMD /usr/games/fortune -a | cowsay.
Build the image: sudo docker build -t wdx-whale . Verify with docker images.
9 Managing Images
Save an image to a tar file: docker save -o wdx-local-whale.tar wdxtub/wdx-whale Load it back with: docker load --input wdx-local-whale.tar Delete an image after removing dependent containers:
sudo docker rmi $(docker images -q -f "dangling=true")10 Container Startup
Run a container in the background with -d:
docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"View its output with docker logs <containerid>.
11 Stop and Restart
Stop a container: docker stop <containerid> Restart a container:
docker restart <containerid>12 Import/Export and Delete
Export a container to a tar archive: docker export <containerid> Import a tar archive as an image: cat ubuntu.tar | sudo docker import - test/ubuntu:v1.0 Delete a stopped container with docker rm; add -f to force removal of a running container.
13 Repository
A repository stores images; a registry is the server that hosts one or more repositories. For example, in dl.dockerpool.com/ubuntu, dl.dockerpool.com is the registry and ubuntu is the repository.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
