容器(Docker)和 CI/CD 强大地协同工作——容器提供一致的构建/测试环境和不可变的部署制品(镜像),而 CI/CD 流水线构建、测试和部署这些镜像。容器解决了交付过程中的关键一致性问题。
容器作为一致的构建/测试环境
→ Run pipeline jobs INSIDE containers → the build/test environment is CONSISTENT and
reproducible (same tools/versions every time, locally and in CI)
→ No "works on my machine" / "works in CI but not locally" environment differences
→ Easy to define the exact environment (a container image with the needed tools)
容器镜像作为部署制品
The pipeline BUILDS a container IMAGE as the deployable artifact:
build → docker build → IMAGE → push to a REGISTRY → deploy the image
✓ the image is IMMUTABLE and self-contained (app + dependencies + runtime)
✓ what you tested IS what you deploy (the same image through environments)
✓ runs identically in any environment (dev, staging, prod, any cloud)
→ Containers are the ideal "build once, deploy everywhere" artifact.
