Skip to content

容器

一句话解释

容器是 lightweight, portable 包那个 bundles application 使用一切它 需要到 运行.

用大白话说

A container is like a box that holds your application along with all its dependencies — libraries, configuration files, and system tools — so it can run the same way on any machine.

Unlike a virtual machine, a container does not include a full operating system. Instead, it shares the host OS kernel, which makes it much lighter and faster to start. A typical container starts in seconds, while a VM might take minutes.

Containers solve the "它工作 on my machine" problem. If your application runs in a container on your laptop, it will run identically in a container on a server, in the cloud, or on a colleague's computer — because everything inside the box is the same.

示例

bash
# Run a Node.js app in a container
docker run -p 3000:3000 my-node-app

这个 command 开始容器从 my-node-app 镜像 and 映射 port 3000 从容器到 host.

工作原理

  1. You write a Dockerfile that describes the application and its dependencies.
  2. You build an image from the Dockerfile.
  3. You run a container from that image.
  4. The container shares the host OS kernel but isolates its own filesystem, processes, and network.

常见混淆

  • 容易混淆的对象: 虚拟 Machine

    关键区别: VM 包含完整 guest OS and 是 heavy; 容器 shares host OS kernel and 是 lightweight.

相关术语

解读错误信息

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

查看错误

← 返回术语表