Inconsistent `pull_policy` behavior with `docker compose` when combining build and image
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- docker, docker-compose
- 领域
- build-system, devops
调研方向
使用 .devcontainer/devcontainer.json 和 compose.yml,通过 @devcontainers/cli up --workspace-folder .. 重现该行为。首先跟踪此入口点如何处理同时定义 image 和 build 的服务,然后将生成的 docker compose 命令与文档中说明的 pull_policy 行为进行比较。当应当拉取镜像或从缓存中找到镜像时,默认工作流不会对 db 运行 docker compose build,即表示完成。
由索引模型根据 Issue 内容生成。
描述
https://docs.docker.com/reference/compose-file/build/#using-build-and-image
https://docs.docker.com/reference/compose-file/services/#image
Using build and image
When Compose is confronted with both a build subsection for a service and an image attribute, it follows the rules defined by the pull_policy attribute.If pull_policy is missing from the service definition, Compose attempts to pull the image first and then builds from source if the image isn't found in the registry or platform cache.
i.e. by default it should pull image from registry/cache before attempting to build when using docker compose up, therefore I expect
.devcontainer/devcontainer.json --- JSON
1
2 {
3 "name": "Repro",
4 "dockerComposeFile": "../compose.yml",
5 "service": "devcontainer",
6 "workspaceFolder": ".",
7 "runServices": [
8 "db"
9 ]
10 }
11
compose.yml --- YAML
1 services:
2 devcontainer:
3 image: mcr.microsoft.com/devcontainers/base:ubuntu
4 volumes:
5 - ../..:/workspaces:cached
6 network_mode: service:db
7 command: sleep infinity
8
9 db:
10 image: postgres:latest
11 build:
12 context: .
13 dockerfile_inline: |
14 FROM postgres:latest
15 restart: unless-stopped
16 volumes:
17 - postgres-data:/var/lib/postgresql/data
18 environment:
19 POSTGRES_PASSWORD: postgres
20 POSTGRES_USER: postgres
21 POSTGRES_DB: postgres
22
23 volumes:
24 postgres-data:
25
(output from git diff)
to not run docker compose build db when running @devcontainers/cli up --workspace-folder .
But it currently runs docker compose --project-name devcontainer-repro -f <abbreviated-path>/devcontainer-repro/compose.yml build db devcontainer
Why this matters:
When trying to prebuild/cache images it is beneficial to have one compose.yml which both defines the image and how to build the image, otherwise you need to split the file in two compose.build.yml and compose.yml. This behavior is inconsistent and confusing.
- 主要语言
- TypeScript
- 星标
- 3k
- 派生
- 461
- 平均合并
- 18 分钟
- 30 天内合并 PR
- 5
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
devcontainers/cli 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 92/100
devcontainers/cli#1203 ·
-
难度 1/5 1-3 小时 新手友好度 68/100
devcontainers/cli#1178 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
devcontainers/cli#1308 ·
-
难度 3/5 1-2 天 新手友好度 78/100
devcontainers/cli#1307 · 1 条评论 · 1 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 55/100
devcontainers/cli#1305 ·
查看 devcontainers/cli 的全部 Issue
相似的 Issue
-
bug(cli): hapi doctor inline-media prints a fabricated B:\ helper-script path in packaged installs 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
-
Crush 未关闭
难度 1/5 1 小时以内 新手友好度 85/100
catppuccin/catppuccin#3125 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
ElementsProject/cln-application#167 · 1 条评论 · 1 个 reaction ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Quantco/pnpm-licenses#17 ·
-
难度 2/5 1-3 小时 新手友好度 75/100