Master Docker in 2 Hours: From Basics to Building and Pushing Images
Within two hours, this guide walks you through Docker fundamentals, explains how containers differ from virtual machines, shows installation on Windows and Ubuntu, details Docker’s architecture, image layering, and provides a hands‑on walkthrough of pulling, running, building, and pushing images to Docker Hub.
In the first two hours you will fall in love with Docker, gaining a basic understanding of its principles and workflow to avoid endless searching for information.
Docker是什么?
KVM, VirtualBox, VMware virtualize whole machines, while Docker virtualizes the operating system to isolate applications, giving each container its own root filesystem, network stack, and PID namespace.
With Docker, two processes can run in separate containers, each seeing its own filesystem and network, even sharing the same PID number without conflict.
Unlike full‑machine virtualization, Docker adds far less overhead because it only virtualizes the application environment.
为什么Docker也可以“虚拟化”?
Virtualization creates an illusion of a separate world; Docker creates isolated namespaces that make each process feel like it has its own OS resources.
安装Docker
For Windows, download Docker Toolbox, close conflicting software (e.g., 360), and run Docker Quickstart Terminal after installation.
For Ubuntu, follow the official docs or simply run sudo apt-get update && apt-get install docker. Add your user to the docker group and restart the Docker service.
Register on Docker Hub to push your own images.
Docker的架构
A typical setup involves a Docker client, a Docker host (daemon) that runs containers, and a Docker registry (default Docker Hub) that stores images. The client issues pull, run, build, and push commands.
image到底是个什么鬼?
A Docker image is a layered filesystem containing the program, libraries, resources, and configuration needed to run a container. Each layer is immutable; changes create a new upper layer, similar to Git diffs.
The topmost layer becomes the running container; modifications inside a container do not alter the underlying image.
一次完整的Docker实作
Step‑by‑step workflow:
1. client用pull命令从仓库把image拉到Docker host
Use docker pull repository/image:tag. The default registry is Docker Hub; if no username is given, library is assumed.
Verify with docker images.
2. 在Docker host上面运行Ubuntu 14.04于containers
Run the image with a command, e.g., docker run -it ubuntu:14.04 /bin/bash, creating a container instance.
Multiple containers can be started from the same image, each acting like a separate process.
3. 构建自己的image
Create a Dockerfile based on ubuntu:14.04 and add RUN apt-get update && apt-get install -y vim gcc to produce a custom image.
Build with docker build -t 21cnbao/myubuntu . and run to verify the new tools are present.
4. 通过docker push把image提交到仓库
Create a repository myubuntu on Docker Hub (full name 21cnbao/myubuntu), log in with docker login, then push with docker push 21cnbao/myubuntu.
After pushing, the image appears in your Docker Hub 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.
