Inconsistent `pull_policy` behavior with `docker compose` when combining build and image
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- docker, docker-compose
- Domain
- build-system, devops
Research direction
Reproduce the behavior with .devcontainer/devcontainer.json and compose.yml using @devcontainers/cli up --workspace-folder .. Start by tracing how this entry point handles services that define both image and build, then compare the generated docker compose command with the documented pull_policy behavior. Done means the default workflow does not run docker compose build for db when the image should be pulled or found in the cache.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 461
- Avg merge
- 18m
- Merged PRs (30d)
- 5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from devcontainers/cli
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
devcontainers/cli#1203 ·
-
Difficulty 1/5 1-3 hours Newbie friendliness 68/100
devcontainers/cli#1178 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
devcontainers/cli#1308 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 78/100
devcontainers/cli#1307 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
devcontainers/cli#1305 ·
All issues in devcontainers/cli
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
dennys-bd/agent-hive#184 ·
-
Add: hunch Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
AbdelStark/awesome-typesafe#104 ·
-
ai-observability bug team/ai-observability
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vicharanashala/fln#563 ·