Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker-compose with multiple files and automatic path extension #10043

Closed
kaninaba94 opened this issue Dec 5, 2022 · 6 comments
Closed

docker-compose with multiple files and automatic path extension #10043

kaninaba94 opened this issue Dec 5, 2022 · 6 comments

Comments

@kaninaba94
Copy link

Description

This is my folder structure:

├── project_root
│   ├── docker-compose.yml
│   ├── volume
│   │       ├── source
│   ├── folder1
│   │   ├── docker-compose.yml
│   │   ├── volume1
│   │       ├── source

docker-compose.yml:

version: "3.4"

services:
    service:
        .
        .
        volumes: ./volume/source:/volume/destination
        .

folder1/docker-compose.yml:

version: "3.4"

services:
    service1:
        .
        volumes: ./volume1/source:/volume1/destination
        .
        .

At the moment, executing docker-compose -f docker-compose.yml -f folder1/docker-compose.yml config from the project-root gives me:

version: "3.4"

services:
    service1:
        .
        .
        volumes: /home/.../project-root/volume/source:/volume1/destination
        .
    service2:
        .
        volumes: /home/.../project-root/volume1/source:/volume1/destination
        .
        .

It would be nice to have an option to combine the two docker files that automically adapts the volume source location according to the host's folder structure, like this:

version: "3.4"

services:
    service1:
        .
        .
        volumes: /home/.../project-root/volume/source:/volume1/destination
        .
    service2:
        .
        volumes: /home/.../project-root/folder1/volume1/source:/volume1/destination
        .
        .

Note the changed volume source location in service2.

@kaninaba94
Copy link
Author

kaninaba94 commented Dec 15, 2022

There would have to be a way to insert the file location into the docker-compose config.

Doesn't anybody else think that this would be a useful feature? It would mean you could more flexibly plug in software modules.

@ndeloof
Copy link
Contributor

ndeloof commented Dec 15, 2022

The way ./ is expanded to actual path in a compose file is a mix of legacy decision, which results sometimes in weird behaviors. I agree we should add support for a "relative to compose file" path notation, but to avoid ambiguities and compatibility break, this would need to rely on a new notation, aside ./path and ~/path we already support.
I'm open to suggestions :)

@kaninaba94
Copy link
Author

My suggestion is to introduce a flag, e.g. --relative-to-compose-file, which would lead to the behavior. That way, we would avoid legacy issues. And perhaps it would be used in more and more systems.

@ndeloof
Copy link
Contributor

ndeloof commented Dec 16, 2022

The risk with a flag is that some users would rely on it on a daily basis but might forget to set the flag, still we can't make this the default behavior. An explicit syntax in the compose file would avoid this issue.

@kaninaba94
Copy link
Author

kaninaba94 commented Dec 16, 2022

If it is possible to have an environment variable named, e.g., CONFIG_PATH that is passed to each config file individually, that would be convenient and would eliminate the need for additional syntax. E.g., if you do docker-compose -f docker-compose.yml -f folder1/docker-compose.yml -f folder2/folder21/docker-compose.yml config, and the individual files look like this:

version: "3.4"

services:
    service:
.
.
        volumes:
            - ./${CONFIG_PATH}/volume_path:volume_path
.
.
version: "3.4"

services:
    service1:
.
.
        volumes:
            - ./${CONFIG_PATH}/volume1_path:volume1_path
.
.
version: "3.4"

services:
    service21:
.
.
        volumes:
            - ./${CONFIG_PATH}/volume21_path:volume21_path
.
.

then CONFIG_PATH would resolve to , folder1 and folder2/folder21 in the resulting config.

Alternatively, the CONFIG_PATH could be resolved to the absolute paths.

@ndeloof
Copy link
Contributor

ndeloof commented May 11, 2023

closing this issue, please see compose-spec/compose-go#335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants