首页/云/Docker 容器速查/compose command 与 entrypoint 覆盖
本包目录(366 条)
基础命令50 条镜像与构建107 条网络与存储52 条
Compose 编排55 条
资源与安全50 条容器排障52 条

compose command 与 entrypoint 覆盖

运行时覆盖镜像的启动命令:command 替换 CMD,entrypoint 替换 ENTRYPOINT;清空入口点用 entrypoint: []。

Docker 容器速查云更新于 2026-10-12
command覆盖镜像 CMD
entrypoint覆盖镜像 ENTRYPOINT
清空entrypoint: [] 后由 command 直接启动

示例

示例
services:
  debug:
    image: app/api:1.4.2
    entrypoint: ["/bin/sh", "-c"]
    command: ["sleep infinity"]
  once:
    image: app/api:1.4.2
    entrypoint: []
    command: ["/app/init-db"]
列表形式避免 shell 解析问题;需要管道/变量替换时显式用 ["sh","-c","…"] 包一层。

易错点

  • 字符串形式与列表形式在参数分割上行为不同,跨版本迁移时优先列表形式
  • 覆盖 entrypoint 后排障容器常用 sleep infinity 保活,别忘了它只用于调试

数据来源与参考

  • Docker 官方文档:Compose command / entrypoint 参考(docs.docker.com/reference/compose-file/services)
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌