Skip to content

镜像

一句话解释

镜像是 读取-仅, 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.

示例

bash
# 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 容器.

工作原理

  1. You write a Dockerfile describing the image contents.
  2. docker 构建 creates the image layer by layer from the Dockerfile.
  3. docker 推送 stores the image in a registry.
  4. docker 运行 creates a container (a running instance) from the image.

常见混淆

  • 容易混淆的对象: 容器

    关键区别: 镜像是 静态, 读取-仅 template; 容器是 运行实例的 镜像使用它的 own filesystem and 处理.

相关术语

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表