To set a simplified scene for my question I will have three compose services: an API server, a site server (for serving browsers the webpage), and a supporting Redis service. The project has the following structure:
app
├── .devcontainer
│ ├── api
│ │ └── devcontainer.json
│ ├── compose.override.yaml
│ └── site
│ └── devcontainer.json
├── api (dir; contents irrelevant for question)
├── compose.yaml
└── site (dir; contents irrelevant for question)
compose.yaml
looks like this
services:
api:
image: python:3.11-slim
command: sleep infinity
site:
image: node:23-slim
command: sleep infinity
cache:
image: redis:7.4.2
.devcontainer/compose.override.yaml
looks like this
services:
api:
volumes:
- .:/app:cached
site:
volumes:
- .:/app:cached
.devcontainer/api/devcontainer.json
looks like this
{
"name": "API",
"dockerComposeFile": ["../../compose.yaml", "../compose.override.yaml"],
"service": "api",
"workspaceFolder": "/app/api"
}
.devcontainer/site/devcontainer.json
looks like this
{
"name": "Site",
"dockerComposeFile": ["../../compose.yaml", "../compose.override.yaml"],
"service": "site",
"workspaceFolder": "/app/site"
}
I can 'reopen' my API service as a dev container, and I can also 'reopen' my site server service as a dev container in another window and it works well. However, I noticed that if I first 'reopen' my API service as a dev container, but then 'rebuild and reopen' my site server service, it will cause the API service dev container to crash and I will then have to 'reload window' for it to work again. This is also true vice-versa. Specifically, the error is Container server: Error response from daemon: No such container: 36a5c9e5d6d4e9630c6fdce9b22c72b3a1230d7eab0f3236996cc707d7bacd2f
; essentially because the container that the VS Code dev container window was using has been recreated due to the rebuild of the other service.
Evaluating 'docker ps' before and after the rebuild shows that rebuilding the site server service causes the API service to be recreated and replaced with a container with a different ID. Interestingly, supporting services like Redis or PostgreSQL do not get replaced, only the services that share the same volume do.
This has led me to believe all services sharing the same volume get rebuilt if another service sharing that volume gets rebuilt. Is this the case? If so, why is this the case? Is there a way to stop this from happening? It obviously gets annoying having to reload the windows of all other services that share the same volume. I've encountered this problem on both MacOS and WSL 2.