devcontainers / devcontainers/cli
devcontainer/cli with docker compose is always reusing existing container
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 457
- Avg merge
- 13h 17m
- Merged PRs (30d)
- 6
Description
I started integrate devcontainer/cli into Jenkins and referenced the [CI-Example](https://github.com/devcontainers/cli/blob/main/example-usage/ci-app-build-script/build-application.sh).
below is reproduce steps (Update: t**he below is not reproduced when not using dockerCompose**):
my .devcontainer :
```javascript
{
"name": "ms-1-ms",
"dockerComposeFile": "docker-compose.yml",
"service": "dev-container",
"workspaceFolder": "/workspace/ms-1",
}
```
my compose :
```javascript
services:
dev-container:
image: "mcr.microsoft.com/devcontainers/base:ubuntu"
command: sleep infinity
volumes:
- ../..:/workspace
```
when i use : `devcontainer up --workspace-folder . --id-label unique=id11`
i get
```shell
[0 ms] @devcontainers/cli 0.58.0. Node.js v16.18.1. darwin 23.3.0 arm64.
[388 ms] Start: Run: docker-compose -f /Users/avishayhirsh/myApps/MicroService1/ms-1/.devcontainer/docker-compose.yml --profile * config
[475 ms] Start: Run: docker-compose -f /Users/avishayhirsh/myApps/MicroService1/ms-1/.devcontainer/docker-compose.yml --profile * config
[551 ms] name: devcontainer
services:
dev-container:
command:
- sleep
- infinity
image: mcr.microsoft.com/devcontainers/base:ubuntu
networks:
default: null
volumes:
- type: bind
source: /Users/avishayhirsh/myApps/MicroService1
target: /workspace
bind:
create_host_path: true
networks:
default:
name: devcontainer_default
[551 ms] Start: Run: docker inspect --type image mcr.microsoft.com/devcontainers/base:ubuntu
[611 ms] Start: Run: docker-compose --project-name ms-1_devcontainer -f /Users/avishayhirsh/myApps/MicroService1/ms-1/.devcontainer/docker-compose.yml build
[749 ms] Start: Run: docker-compose --project-name ms-1_devcontainer -f /Users/avishayhirsh/myApps/MicroService1/ms-1/.devcontainer/docker-compose.yml -f /var/folders/q9/6t3mffmn3dz_bcv3zhmkkgzh0000gq/T/devcontainercli/docker-compose/docker-compose.devcontainer.containerFeatures-1712474784059.yml up -d
[+] Running 1/2
⠹ Network ms-1_devcontainer_default Created 0.2s
✔ Container ms-1_devcontainer-dev-container-1 Started 0.2s
{"outcome":"success","containerId":"2c0721ac05bbf2eed047e58e34577e310a30dd75d6d5e6940b935cfe21c469ac","composeProjectName":"ms-1_devcontainer","remoteUser":"vscode","remoteWorkspaceFolder":"/workspace/ms-1"}
```
So far so good , now i want to spawn a new dev container (to simulate parallel dev containers running in the jenkins machine)
`devcontainer up --workspace-folder . --id-label unique=id44242`
but i get
```shell
[1 ms] @devcontainers/cli 0.58.0. Node.js v16.18.1. darwin 23.3.0 arm64.
{"outcome":"success","containerId":"2c0721ac05bbf2eed047e58e34577e310a30dd75d6d5e6940b935cfe21c469ac","composeProjectName":"ms-1_devcontainer","remoteUser":"vscode","remoteWorkspaceFolder":"/workspace/ms-1"}
```
So it is reusing the same container while i do not want to reuse the same container , nor to remove the existing i need to run a new dev container with the specific label ....
Maybe this is due to docker compose functionality but i would expect the devcontainer/cli to maybe generate new project name when it detects a different label or something ? because if the cli will create a unique project name in such case it would be able to spawn a new dev container instance... WDYT ? (or at least document that this is limitation of --id-label ?)
Though, using a unique compose project name will result with volumes not be shared across dev containers , so the only solution right now i think of is to drop usage of compose in CI flow , and rather generate a .devcontainer.json on the fly without compose in pipeline or to create devcontainer-ci.json that will not include compose, this way the problem is solved and also the volumes are shared.
Contributor guide
Assessment
This issue has not been assessed yet.