-
Notifications
You must be signed in to change notification settings - Fork 299
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
Adjustable project-name flag for docker-compose #512
Comments
Related: #222 |
We should also check for COMPOSE_PROJECT_NAME in .env or ENV. |
I'm really interested in this feature, to be consistent with how docker-compose works. |
I have the same issue. |
Maybe custom (remote) project name could also be defined in the devcontainer.json file? |
I got the same issue, it will be very helpful if we can check COMPOSE_PROJECT_NAME in .env -----temporary solution------ directory structure as below:
devcontainer.json as below: vscode will get: |
I'm also quite interested. managing directory naming is a pain when multiple developers are working on the same server. Managing this from either the .env file or devcontainer.json would be ideal I think. |
+1 I also want to override the project_name. I have directories that has a different name but almost the same docker compose. I need to remove container when I switch the directory. |
I was wondering if there's a fix other than what @zhijian720 mentioned? |
#979 (closed as a dupe of this issue) and #2645 (incorrectly closed with "working as described") give the best explanation for this issue. The official docs still say:
And yet, VS Code will in fact always bring up containers with
This CLI arg seems to override |
@mrmachine Using the |
I made the environment variable work a while back. You seem to describe a regression and I would appreciate a separate issue so I can follow up. This issue is tracking the addition of a property to the devcontainer.json for the project name - the way I interpret it. |
Yes, that's the point of this feature-request, to allow specifying project-name (for docker-compose) in .devcontainer.json so you don't have to create a .env file in the root of your project and set the COMPOSE_PROJECT_NAME variable there. |
Are there any updates? I would also like to set the |
@odannyc Not at this moment. It is best to 👍 the issue's description to add your vote. |
а если еще внутри docker-compose топ-то docker in docker COMPOSE_PROJECT_NAME в .env не могу задать потому что он воссияет на внутренний докер |
I would like to add an additional note as to the benefit of configuration in There are a lot of tools, which structure themselves around managing environment via a |
I have met this problem when I was preparing a dev environments for the whole team on a shared server. The docker compose project name will always be collised when two dev members open the same code project. Think of the "Clone Repository in Container Volume" scene. And every dir name and structure will be the same. Finally I found a solution. Use devcontainer.json |
I used @crhan solution to my problem. I needed devcontainer to not collide with standard docker-compose usage, I think @gwax might have had the same problem. What I did is create
|
The above "initializeCommand" trick creating |
@chrmarti It's a very confusing choice to have the compose project name come from a |
I might be missing the point of having the extension pass Doesn't Docker Compose already use the directory name if you omit the option? It should also be possible to set the project name in the version: "3.9"
name: my-project-name # <----- used as prefix for volumes etc.
services:
app: # ...
volumes:
app-data: # <----- my_project_name__app-data Currently the extension overrides the |
As far as I can tell, Here's how you would do it in bash, but can be easily modified to work in Node.js: $ docker-compose -f docker-compose.yml config --format json | jq .name
"my-project-name" This reuses the logic built in to Docker Compose to determine the project name:
This can be implemented in a fully backwards-compatible way. Using a (*) might be problematic if the only config file is the one in cc @chrmarti |
@sliekens Great find, and yes an even better approach to just go with docker defaults. All of my Docker related files are in a subdir |
The lack of support for using |
Env vars are checked first to enable multiple instances of a compose project. $ COMPOSE_PROJECT_NAME=main docker-compose up -d [+] Running 4/4 ✔ Network main_default Created 0.1s ✔ Volume "main_postgres-data" Created 0.0s ✔ Container main-db-1 Started 0.1s ✔ Container main-devcontainer-1 Started 0.1s $ COMPOSE_PROJECT_NAME=alt docker-compose up -d [+] Running 4/4 ✔ Network alt_default Created 0.1s ✔ Volume "alt_postgres-data" Created 0.0s ✔ Container alt-db-1 Started 0.1s ✔ Container alt-devcontainer-1 Started For my projects, I put a static |
I am running into this issue too where I would like to use the top level name: in my docker compose file to set the compose project name. .env is not enough because I would like it to be changed by another environment variable. I can do this is a compose file but not .env. |
In a shared machine, a .devcontainer is git checked-in and therefore shared by multiple developers. The issue is that if you don't offer a convenient way to change the project name people's different variants of the devcontainer (due to changing dockerfile a bit to suit personal needs) are going to collide with each other and cause issues. Container name is another thing that should be able to overriden in devcontainer.json |
#7377 (comment) according to this comment it should be back to working again. |
Yes I was able to use the initilizeCommand and postCreateCommand to do what I need as a work around. The difference for me was I already had a .env so needed to append to it, then remove just the line that was changed. Hoping this will be fixed in the future by respecting the top-level name: in a docker compose file. |
I didn't use initializeCommand because our use case demand each user to fully isolate with other user's containers, so I wrote up a similar script like the previous suggested code, the idea is to replace the container_name and generate a .env file (project_name) with |
I'm surprised that it will not use the docker compose .env file in the .devcontainer folder, instead it has to be at the root of the project. So I need to programatically create two .envs.. which is not a good looking solution. |
It needs to be next to the docker-compose.yml. This is given by Docker Compose: https://docs.docker.com/compose/environment-variables/set-environment-variables/ |
Fixing by adding support for the name attribute in the compose file. |
Thank you @chrmarti! I will feel the benefit of this improvement many times over! |
This is now available with Dev Containers 0.365.0-pre-release. Let us know if it works (or doesn't!) for you, thanks! |
Yes that worked for me. I tried it out yesterday and it didn’t but now it does. Making sure there is no environment variable, I see the “docker compose ls” project name was changed with the name value in docker compose. I updated my dev container extension to the newest release, removed the initializeCommand and postCreateCommand from devcontainer.json that setup the old environment variable, I then added the top level name attribute to docker-compose.yml, deleted the old compose instance and container then with vscode rebuild the container and compose environment. One thing to mention is I was using the username of the person who ran it to make the compose name unique. This worked with bash because I would make the username lowercase. Now using “name: project_${USER}” doesn’t work because docker wants it to be lower case. Now just looking into a way to keep it unique and valid. |
It works for me. PS: don't forget to update https://code.visualstudio.com/remote/advancedcontainers/set-docker-compose-project-name. PS (2): this only works with docker compose V2, i.e. the plugin for In Azure Pipelines, these versions are installed: $ docker-compose version
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
$ docker compose version
Docker Compose version v2.23.3 In this scenario, it is necessary to pass I suspect it would be better if the devcontainer CLI would detect if |
@sliekens Thanks, updating the docs here: microsoft/vscode-docs#7377 We automatically use |
Currently, the docker-compose command seems to base
--project-name
off of the parent/project folder.Launching containers from two sub-folders of a root project, seems to namespace them in separate areas. I've yet to find a way to override this. While this may work when both containers are inheriting from a top level docker-compose file, this would mean major refactoring of our repositories to match our IDE, rather than just specifying a flag to launch related projects under the same namespace.
As an example:
devcontainer1/devcontainer.json
expandsProject1/docker-compose.yml
, creating Docker networks/assets prepended withProject1_
.devcontainer2/devcontainer.json
expandsProject1.componentX/docker-compose.yml
, which then either fails, as it's referencing Docker networks/assets with no prefix, or creates assets with the now incorrect prefix ofProject1.componentX
if assets are created explicitly.The text was updated successfully, but these errors were encountered: