镜像
一句话解释
镜像是 读取-仅, layered template 那个包含一切需要到 运行 containerized application.
用大白话说
A Docker image is a read-only template that contains your application and everything it needs to run — code, libraries, environment variables, and configuration files. You run a container from an image.
Images are built from a Dockerfile and are composed of layers. Each instruction in the Dockerfile creates a new layer. Layers are cached and shared between images, which makes builds fast and images small.
Images are identified by a name and a tag (e.g., nginx:latest, myapp:1.2.3). The tag latest is the default but should be avoided in production — always use specific version tags so you know exactly what you are deploying.
示例
# Build an image from a Dockerfile
docker build -t myapp:1.0 .
# List images on your machine
docker images
# Run a container from the image
docker run -p 80:80 myapp:1.0构建镜像 tagged myapp:1.0 从 Dockerfile in current directory, 然后运行它 as 容器.
工作原理
- You write a Dockerfile describing the image contents.
docker 构建creates the image layer by layer from the Dockerfile.docker 推送stores the image in a registry.docker 运行creates a container (a running instance) from the image.
常见混淆
容易混淆的对象: 容器
关键区别: 镜像是 静态, 读取-仅 template; 容器是 运行实例的 镜像使用它的 own filesystem and 处理.
相关术语
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。