Skip to content

Docker

一句话解释

Docker 是 platform 那个 lets 你构建, ship, and 运行 applications in 容器.

用大白话说

Docker 是the most popular tool for working with containers。 It provides a simple command-line interface to build images, run containers, and manage them.

With Docker, you write a Dockerfile — a text file that describes what goes into your container (base image, dependencies, your code). Then you use the docker 构建 command to create an image, and docker 运行 to start a container from that image.

Docker also provides Docker Hub, a public registry where you can find pre-built images for common software like Node.js, Python, PostgreSQL, and thousands more. You can use these as base images for your own applications.

示例

dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "start"]

这个 Dockerfile 创建节点.js 镜像: 开始从 official 节点镜像, 安装 dependencies, 复制 code, and 运行 app.

工作原理

  1. Write a Dockerfile describing your application environment.
  2. Run docker 构建 to create an image from the Dockerfile.
  3. Run docker 运行 to start a container from the image.
  4. Use docker ps to list running containers and docker logs to view output.

常见混淆

  • 容易混淆的对象: Kubernetes

    关键区别: Docker 运行 individual 容器 on one machine; Kubernetes orchestrates 许多容器跨越多个 machines.

相关术语

解读错误信息

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

查看错误

← 返回术语表