Master Docker: From Basics to Advanced Container Management
This comprehensive guide introduces Docker, explains its core concepts such as images, containers, and registries, walks through installation on various platforms, demonstrates essential commands, shows how to build, run, and manage containers and images, and covers advanced topics like exporting, importing, and using web UI tools.
Introduction
Docker, originally an internal project of dotCloud and written in Go, provides lightweight OS-level virtualization that dramatically speeds up software development and deployment. It replaces traditional virtual machines with containers that share the host kernel, offering higher resource efficiency and faster startup.
Quick Start
Docker began as an internal hobby project.
It is built with Go.
Its goal is a lightweight OS virtualization solution.
It is based on Linux containers (LXC) and similar technologies.
Containers start in seconds, far faster than VMs.
A single host can run thousands of containers.
Main Advantages
Faster delivery and deployment – containers are the smallest unit.
More efficient virtualization – kernel‑level.
Easier migration and scaling.
Simpler management.
Installation
Official documentation provides installation guides for Mac, Linux, and Windows. Follow the official steps; no additional details are needed here.
Kitematic (Visual Docker Container Management on Mac & Windows) is a helpful GUI tool for beginners.
Daemon
Run the Docker daemon with custom bind options, e.g., sudo /usr/bin/docker -d -H tcp://0.0.0.0:2375. To avoid typing this each time, set the environment variable export DOCKER_HOST="tcp://0.0.0.0:2375".
Graphical User Interface
Common web management interfaces include Shipyard and Portainer.
Basic Concepts
The three core concepts are:
Image : a read‑only template used to create containers; layered via a Union file system.
Container : a running instance created from an image, with its own writable layer, isolated processes, and its own root file system.
Registry : a storage location for images, public (Docker Hub) or private.
What Docker Can Do
Standardize, optimize, and accelerate local development and build pipelines.
Ensure consistent results across environments.
Create isolated test environments.
Isolation Types
File‑system isolation – each container has its own root FS.
Process isolation – separate process spaces.
Network isolation – separate virtual interfaces and IPs.
Resource isolation – cgroups allocate CPU, memory, etc.
Common Commands
sudo docker info– view Docker status. docker ps – list running containers ( -a for all, -l for the latest).
Simple Example
Create and run a container: docker run ubuntu:14.04 /bin/echo 'Hello wdx!' The command prints Hello wdx! as expected.
Start an interactive bash session: docker run -t -i ubuntu:14.04 /bin/bash Options: -t allocates a pseudo‑TTY, -i keeps STDIN open.
Running Commands Inside a Container
cat /etc/hosts ip a ps -aux cd ~ && echo "hello wdx" > hello.txt && cat hello.txtAfter exiting, the container still exists and can be inspected with docker ps -l.
Images
Pull images from a registry: sudo docker pull ubuntu:12.04 Specify a custom registry if needed, e.g., sudo docker pull dl.dockerpool.com:5000/ubuntu:12.04.
List local images:
docker imagesRunning an Image
Example with the whalesay image: docker run docker/whalesay cowsay boo The container prints a whale saying “boo”.
Building an Image
Create a Dockerfile:
FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsayBuild the image: sudo docker build -t wdx-whale . Verify with docker images.
Pushing to a Registry
Tag the image: docker tag 26ac9649d7da wdxtub/wdx-whale:latest Login and push:
docker login --username=wdxtub [email protected]
docker push wdxtub/wdx-whaleManaging Images
Export an image to a tar file:
docker save -o wdx-local-whale.tar wdxtub/wdx-whaleImport it back: docker load --input wdx-local-whale.tar Remove dangling images:
sudo docker rmi $(docker images -q -f "dangling=true")Import/Export and Deletion
Export a container:
docker export <span>containerid</span> > container.tarImport a container snapshot as an image:
cat ubuntu.tar | sudo docker import - test/ubuntu:v1.0Delete containers:
docker rm <span>containerid</span>
# Remove all stopped containers
docker rm $(docker ps -a -q)Registry
A registry stores images; Docker Hub is the public registry, while private registries can be set up for internal use.
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.
