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

COMPOSE_PROJECT_NAME not used #5561

Open
bluebrown opened this issue Sep 9, 2021 · 6 comments
Open

COMPOSE_PROJECT_NAME not used #5561

bluebrown opened this issue Sep 9, 2021 · 6 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug containers Issue in vscode-remote containers

Comments

@bluebrown
Copy link

Hi, using the COMPOSE_PROJECT_NAME doesn't appear to be working correctly. I don't have the .env at the root of my workspace, but next to my docker-compose file in a subdirectory. Strange enough. Other env variables from this .env file are read and used by compose as build args. So I know it's not an issue with the placement in terms of compose. It seems to be that vscode differs here and needs to have it at the root of the project.

├── .devcontainer
│   ├── devcontainer.json
│   └── docker-compose.patch.yaml
├── .docker
│   ├── .env
│   ├── docker-compose.yaml
├── Dockerfile

I can start compose with the below and the env vars, including COMPOSE_PROJECT_NAME , are respected and used.

docker-compose  -f .docker/docker-compose.yaml up

Even when starting the devcontainer referencing this composes file. The env vars are used as build args as mentioned initially.

"dockerComposeFile": [
    "../.docker/docker-compose.yaml",
    "./docker-compose.patch.yaml"
]

But unfortunately, when using the container the resulting container are prefixed with docker_, unlike when using compose -f like shown above.

$ code -v
1.60.0
e7d7e9a9348e6a8cc8c03f877d39cb72e5dfb1ff
x64
@github-actions github-actions bot added the containers Issue in vscode-remote containers label Sep 9, 2021
@chrmarti
Copy link
Contributor

Compose changed from reading the .env file from the current working directory to the first compose file's folder. (#4560) We could check the version of Compose to know where to look for the file.

@chrmarti chrmarti added the bug Issue identified by VS Code Team member as probable bug label Sep 15, 2021
@chrmarti chrmarti self-assigned this Sep 15, 2021
@davidrios
Copy link

I'm having this same issue. I've set up an example repository: https://github.com/davidrios/devcont-compose-project

If I open folder src/vscode in container, it tries to start the compose file with project name src, it doesn't respect src/.env, which fails if I have the project already running, because of ports already bound.

If I put a .env file with COMPOSE_PROJECT_NAME in the src/vscode, it uses that.

It seems from the logs it forces a --project-name parameter:

[1590 ms] Start: Run: docker-compose --project-name src -f /home/david/work/devcont-compose-project/src/docker-compose.yaml -f /tmp/docker-compose/docker-compose.devcontainer.containerFeatures-1649517707434.yml up -d

If it didn't pass that argument, docker-compose would pick up the correct project name from the env file.

@i-ky
Copy link

i-ky commented Dec 11, 2023

Compose changed from reading the .env file from the current working directory to the first compose file's folder. (#4560) We could check the version of Compose to know where to look for the file.

@chrmarti, is there any update? Do you still have plans to change extension's (or devcontainer CLI) behaviour as described?

For latest versions of Docker Compose (those that support Compose Specification) it can be even simpler - docker config outputs the name: of the project.

@chrmarti
Copy link
Contributor

The reason we got into overwriting the project name is that the docker-compose.yml often is in the .devcontainer folder and that lets Docker Compose pick devcontainer as the project name by default which is non-unique. We want to keep overriding that, but not override any user-supplied project name. Not sure in which Docker Compose version name: was added to docker compose config, but we could potentially use that check if we need to overwrite the project name.

@i-ky
Copy link

i-ky commented Dec 12, 2023

Not sure in which Docker Compose version name: was added to docker compose config, but we could potentially use that check if we need to overwrite the project name.

Looks like it was added in Docker Compose 2.3.0:

... which in turn added:

@jjshinobi
Copy link

Is there a plan to support name property in docker compose config? IntelliJ dev containers support it already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug containers Issue in vscode-remote containers
Projects
None yet
Development

No branches or pull requests

5 participants