Relative paths from templates in subdirectory is not resolved correctly
Description
I've read this issue: https://github.com/docker/compose/issues/3874 They are similar but not exactly the same.
I understand that when using multiple compose config files, the parent dir of the first file would be considered as project root, and all relative paths should be resolved against it. Actually it's what I've expected, however it's not the case when using extends.
I've created the following minimal project to demo the issue I'm facing:
https://github.com/allenhsu/demo-docker-compose-extends
I have a root docker-compose.yml file, a sub config in docker-compose.d/test.yml which extends service from docker-compose.d/templates.yml. Relative paths defined in docker-compose.d/test.yml are correctly resolved against the project root, while those defined in docker-compose.d/templates.yml are not.
Steps to reproduce the issue:
- Clone the demo repo
- Run
docker compose config
Describe the results you received:
services:
test1:
...
test2:
...
test3:
extends:
file: docker-compose.d/templates.yml
service: template
image: alpine:latest
networks:
default: null
volumes:
- type: bind
source: /Users/allen/Workspace/test/docker-extends/docker-compose.d/test
target: /mnt/test_template
bind:
create_host_path: true
test4:
extends:
file: docker-compose.d/templates.yml
service: template
image: alpine:latest
networks:
default: null
volumes:
- type: bind
source: /Users/allen/Workspace/test/docker-extends/test
target: /mnt/test4
bind:
create_host_path: true
- type: bind
source: /Users/allen/Workspace/test/docker-extends/docker-compose.d/test
target: /mnt/test_template
bind:
create_host_path: true
...
Describe the results you expected:
I expect the relative paths from the template file also resolved against the project root, meaning the source of /mnt/test4 and /mnt/test_template should be identical in service test4.
Additional information you deem important (e.g. issue happens only occasionally):
Output of docker compose version:
Docker Compose version v2.2.3
Output of docker info:
Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc., v0.7.1)
compose: Docker Compose (Docker Inc., v2.2.3)
scan: Docker Scan (Docker Inc., v0.16.0)
Server:
Containers: 6
Running: 2
Paused: 0
Stopped: 4
Images: 12
Server Version: 20.10.12
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc version: v1.0.2-0-g52b36a2
init version: de40ad0
Security Options:
seccomp
Profile: default
cgroupns
Kernel Version: 5.10.76-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: aarch64
CPUs: 4
Total Memory: 3.841GiB
Name: docker-desktop
ID: 6H4Z:LFSH:DJM3:I2TZ:DLA3:LBNP:BFZZ:LOI7:BHDS:34VU:NMSB:3DAS
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Additional environment details: N/A
Thanks for reporting this issue with a detailed reproduction example.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed because it had not recent activity during the stale period.