Description
Right now docker compose up doesn't build all the necessary dependencies.
After some digging, this is caused by the changes made for this PR #12729
I would expect that building works the same if it's done by up or build
Steps To Reproduce
Given this configuration
services:
main:
build:
dockerfile_inline: |
FROM alpine
additional_contexts:
dep1: service:dep1
dep2: service:dep2
entrypoint: ["echo", "Hello from main"]
dep1:
build:
dockerfile_inline: |
FROM alpine
additional_contexts:
subdep1: service:subdep1
subdep2: service:subdep2
entrypoint: ["echo", "Hello from dep1"]
dep2:
build:
dockerfile_inline: |
FROM alpine
entrypoint: ["echo", "Hello from dep2"]
subdep1:
build:
dockerfile_inline: |
FROM alpine
entrypoint: ["echo", "Hello from subdep1"]
subdep2:
build:
dockerfile_inline: |
FROM alpine
entrypoint: ["echo", "Hello from subdep2"]
docker compose up fails with failed to find target subdep1 or failed to find target subdep2
When I run docker compose build it works fine. but docker compose up --build also fails.
Compose Version
Docker Compose version v2.37.0-3-g8151b5928
Docker Environment
Client: Docker Engine - Community
Version: 28.2.2
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.24.0
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.37.0-3-g8151b5928
Path: /home/user/.docker/cli-plugins/docker-compose
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 34
Server Version: 28.2.2
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
CDI spec directories:
/etc/cdi
/var/run/cdi
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
runc version: v1.2.5-0-g59923ef
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.8.0-60-generic
Operating System: Ubuntu 22.04.5 LTS
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 31.06GiB
ID: 2b2e89ad-9b8a-4a55-987b-9e9edf5b2b94
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
::1/128
127.0.0.0/8
Live Restore Enabled: false
Anything else?
The services used in the project are filtered here cmd/compose/compose.go#L365, it checks if it's in the depends_on: if it's not, it's removed
the function that recursively gets all build dependencies uses additional_contexts, but since all services were filtered out, except the main one, it can only go one level deep.
If I add use depends_on: together with additional_context: the issue is solved.
services:
main:
build:
dockerfile_inline: |
FROM alpine
additional_contexts:
dep1: service:dep1
dep2: service:dep2
entrypoint: ["echo", "Hello from main"]
depends_on:
- dep1
- dep2
dep1:
build:
dockerfile_inline: |
FROM alpine
additional_contexts:
subdep1: service:subdep1
subdep2: service:subdep2
entrypoint: ["echo", "Hello from dep1"]
depends_on:
- subdep1
- subdep2
Not sure if it's something worth fixing/changing or just something that should be explicit in the docs
Description
Right now docker compose up doesn't build all the necessary dependencies.
After some digging, this is caused by the changes made for this PR #12729
I would expect that building works the same if it's done by up or build
Steps To Reproduce
Given this configuration
docker compose upfails withfailed to find target subdep1orfailed to find target subdep2When I run
docker compose buildit works fine. butdocker compose up --buildalso fails.Compose Version
Docker Environment
Anything else?
The services used in the project are filtered here cmd/compose/compose.go#L365, it checks if it's in the
depends_on:if it's not, it's removedthe function that recursively gets all build dependencies uses additional_contexts, but since all services were filtered out, except the main one, it can only go one level deep.
If I add use
depends_on:together withadditional_context:the issue is solved.Not sure if it's something worth fixing/changing or just something that should be explicit in the docs