vscode-remote-release
vscode-remote-release copied to clipboard
Add ability to specify container name in `devcontainer.json`
It would be great to be able to specify a default container name rather than the autogenerated name provided via VSCode.
I could rename the container afterwards but without knowing what the name of the container will be when first generated, it's non-trivial to automate this.
My use case is knowing the name of my development container so I can use volumes-from to pass its volumes to any new containers it creates.
In the docker-compose.yml I set the container_name: XXX and my container is named XXX in such case.
I just curious now, why VS Code auto-generates the group for containers automatically, like {ProjectFolderName}_devcontainer and how to specify my custom name for the Docker container group.
Container group name is metadata. Container metadata is passed to the Docker via labels. labels can be passed to the Docker engine using runArgs[]. The Container name is not metadata - this is DNS name of the container on the Corresponding Docker network and meaningful display value for the individual container.
Is there a way to leverage the docker compose project-name (now called top-level name) as for the devcontainer group name?
# docker-compose.yml
name: sql-server
services:
az-sql:
container_name: azure-sql
image: mcr.microsoft.com/azure-sql-edge:latest
ports:
- 1433:1433
volumes:
- sql-data:/data
volumes:
sql-data:
name: sql-data
The name: sql-server is now used as the container group name with the docker compose v2.3.3. Previously in docker, this is the folder name. So the question is how do I leverage this when using .devcontainer.json instead of passing via runArgs: []?
Container group name is metadata. Container metadata is passed to the Docker via labels. labels can be passed to the Docker engine using runArgs[]. The Container name is not metadata - this is DNS name of the container on the Corresponding Docker network and meaningful display value for the individual container.
Put a row like this one in your .devcontainer.json:
"runArgs": ["--name", "${localEnv:USER}_devcontainer"]
Hello, is there a possibility to change the dev container image repository, for now it is vsc-${BASE_IMAGE}-${HASH} ?
I was expecting that name would be reflected as the container name or that there'd be some setting for it. It'd be nice if I got to choose the name - easier for me to look at the container names than the images to see which one's which.
To set the docker project and container names I currently use:
- an
.envfile in the project's root folder withCOMPOSE_PROJECT_NAME=my-project(see documentation) - optional: set
container_name: my-containerin thedocker-compose.ymlbelow the service
So I can have several devcontainer projects with the same folder name running at the same time.
Hello, is there a possibility to change the dev container image repository, for now it is vsc-${BASE_IMAGE}-${HASH} ?
The Dev Container extension auto clone the image we used and set the name vsc-${BASE_IMAGE}-${HASH}, then create the container from it. I cannot understand why it do that? Please fix it in current versions, if the extension want to add features, let do it directly in container and don't create new image! Finally I rollback to version 0.238.2 and don't get this issue.
Put a row like this one in your .devcontainer.json:
"runArgs": ["--name", "${localEnv:USER}_devcontainer"]
It would be good to have this as a comment in the generated .devcontainer.json
these seems to address container name, but what about image name....an image name like this is very unsexy and unpleasing to the eye when viewing docker processes
vsc-myapp-69e5361f2a0ac432981344b94b2fb69bab00834cd7db4c4b402e7138c6b65c25-uid
is there any work on this request ?
This would be good
Container group name is metadata. Container metadata is passed to the Docker via labels. labels can be passed to the Docker engine using runArgs[]. The Container name is not metadata - this is DNS name of the container on the Corresponding Docker network and meaningful display value for the individual container.
Put a row like this one in your .devcontainer.json:
"runArgs": ["--name", "${localEnv:USER}_devcontainer"]
my goodness...so glad i dont have to explain what their weird names are during demos anymore. now if we can ust get rid of the vsc-fkldlsjsfjajfajdf;kjas;kfljakldjf;alsjdf;lkajsf;lajsdflkjdkljfldjlfjldjflsjdlsdjfjldjflsdjlfjsdl
+1
Container group name is metadata. Container metadata is passed to the Docker via labels. labels can be passed to the Docker engine using runArgs[]. The Container name is not metadata - this is DNS name of the container on the Corresponding Docker network and meaningful display value for the individual container.
Put a row like this one in your .devcontainer.json:
"runArgs": ["--name", "${localEnv:USER}_devcontainer"]
The 1st quote is for post graduates.
The 2nd quote is for undergraduates.
This one is for you:
"runArgs": ["--name", "hello-world"],
I got stuck adding multiple parameters and figured out.
"runArgs": [
"--network=host",
"--name", "hello-world"
],
Do you have any link regarding the runArgs field? I've only found vague references to it but no actual documentation
these seems to address container name, but what about image name....an image name like this is very unsexy and unpleasing to the eye when viewing docker processes
vsc-myapp-69e5361f2a0ac432981344b94b2fb69bab00834cd7db4c4b402e7138c6b65c25-uid
What I do here, is manually pull the image from the .devcontainer.json that was generated by vscode. Before I open it up vscode as a container.
To set the docker project and container names I currently use:
- an
.envfile in the project's root folder withCOMPOSE_PROJECT_NAME=my-project(see documentation)- optional: set
container_name: my-containerin thedocker-compose.ymlbelow the serviceSo I can have several devcontainer projects with the same folder name running at the same time.
Thank you. It also works with several users on the same server. You helped me a lot.
Regarding volumes: it would be great if the project name provided in .devcontainer/devcontainer.json or .devcontainer/compose.yaml could also be used in the volume labels:
docker compose -f .devcontainer/compose.yaml up -d app
WARN[0000] volume "devcontainer_enhancements_data" already exists but was created for project "devcontainer-enhancements_devcontainer" (expected "devcontainer_enhancements_devcontainer"). Use `external: true` to use an existing volume
It seems like the volume itself was created with the name devcontainer_enhancements_data, but the label was auto-generated by Dev Containers as devcontainer-enhancements_devcontainer.
Container group name is metadata. Container metadata is passed to the Docker via labels. labels can be passed to the Docker engine using runArgs[]. The Container name is not metadata - this is DNS name of the container on the Corresponding Docker network and meaningful display value for the individual container.
Put a row like this one in your .devcontainer.json:
"runArgs": ["--name", "${localEnv:USER}_devcontainer"]
Thank you for this, @rentom
Since we ran into the same container-name collisions with Docker Compose, we built a tiny init script to generate COMPOSE_PROJECT_NAME from your local path - so every clone gets a deterministic, collision-free name:
- Sanitizes your local path into
COMPOSE_PROJECT_NAME - Writes it into
.devcontainer/.envbefore Compose runs
Minimal example here: https://github.com/reinoxl/unique-devcontainer-name-with-docker-compose.git
Maybe this could be helpful for someone.