Master Docker: From Origins to Commands, Networking, and Volumes
This guide explains Docker’s origins, core container technologies such as cgroups and namespaces, essential commands for managing container lifecycles, and practical examples covering environment variables, volumes, and networking, enabling readers to understand and operate Docker containers effectively.
Overview
Origin
Docker was open‑sourced in 2013 by DotCloud, a PaaS provider, reflecting its original focus on container management.
Technical Principles
Initially built on LXC, Docker relies on two Linux kernel features:
cgroup : groups processes for unified resource control (CPU, memory, etc.).
namespace : provides each group with isolated PID, IPC, and network spaces.
Pain points addressed
Packaging and deployment.
Standardizing runtime environments.
More efficient utilization of physical machines.
Docker basic commands
Container lifecycle (create, start, stop, restart, remove)
docker pull busybox – download an image.
docker run -it --rm --name busybox busybox – create and run a container.
docker stop/kill busybox – stop or force‑stop a container.
docker start/restart busybox – start or restart a container.
docker rm busybox – remove a container.
Common commands
docker exec – run a command inside a running container.
docker cp – copy files between host and container.
docker inspect – view detailed information about containers or images.
docker stats – display resource usage of containers.
docker events – stream Docker daemon events.
docker logs – view container logs.
docker top – list processes running inside a container.
Docker usage examples (busybox)
Containers are isolated, but interaction with the host or other containers is possible via environment variables, volumes, and networking.
Environment variables
docker run -it --rm -e MY_NAME=wangyubin busybox envVariables defined on the host can be injected at container start.
Volumes (disk)
docker volume ls # list volumes
docker volume inspect VOL_NAME # inspect a specific volumeFiles created inside a container do not modify the underlying image.
docker run -it --rm busybox
# touch test.txt
# ls
...When the container is restarted, the file disappears because it was not stored in a volume.
Mounting a host directory shares files between containers:
docker run -it --rm -v /home/wangyubin/tmp/volume:/share-dir busybox
cd /share-dir
touch test.txtAnother container can mount the same directory and see test.txt.
Networking
By default, a container’s services are reachable only from inside the container.
Expose ports to the host
docker run -it -p 1234:1234 --rm busybox
# nc -l -p 1234The exposed port appears in docker ps and can be accessed from the host.
Containers on the same network
docker network create test
docker network ls
docker run -it --rm --name test01 --network test busybox
# nc -l -p 1234
docker run -it --rm --name test02 --network test busybox
# nc test01 1234Containers sharing a user‑defined network can address each other by name; containers on different networks cannot communicate.
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.
