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.
示例
FROM node:18-alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "start"]这个 Dockerfile 创建节点.js 镜像: 开始从 official 节点镜像, 安装 dependencies, 复制 code, and 运行 app.
工作原理
- Write a Dockerfile describing your application environment.
- Run
docker 构建to create an image from the Dockerfile. - Run
docker 运行to start a container from the image. - Use
docker psto list running containers anddocker logsto view output.
常见混淆
容易混淆的对象: Kubernetes
关键区别: Docker 运行 individual 容器 on one machine; Kubernetes orchestrates 许多容器跨越多个 machines.
相关术语
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。