最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

docker compose - VS Code multi-container dev containers - rebuild and reopen wrongly rebuilds other services - Stack Overflow

programmeradmin2浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论