I have a very simple Docker project setup with a vscode devcontainer.
There are two Docker containers, dev and db
This works! I open the project in the devcontainer and everything works fine, until i have to rebuild the container: When I do the vscode devcontainers: Reload container command the dev service container is closing and deleted as expected. However, the db service container is not. The restart policy even set to "no", it just refuses to shut down at all, causing a new error because the new rebuilder db container wants to use the port that is still in use on the old container.
It looks like the default setting in devcontainer.json "shutdownAction": "stopCompose" is completely ignored by Docker or by the db container itself. (i tried to explicitly set that setting in the devcontainer.json as well without success).
Here are the relevant files:
docker-compose.yml
services:
dev:
container_name: trading-platform-dev
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3001"
volumes:
- .:/workspace:cached
depends_on:
- db
tty: true
stdin_open: true
db:
container_name: trading-platform-db
image: postgres:17-alpine
restart: "no"
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: trading_platform_db
ports:
- "5432:5432"
volumes:
- postgres_dev_data:/var/lib/postgresql/data
volumes:
postgres_dev_data:
Dockerfile
FROM node:22-slim
# Install Required packages
RUN apt-get update && apt-get install -y openssl curl git
# Activate Corepack
RUN corepack enable
# Disable npm update notifier
RUN npm config set update-notifier false --global
# Create and set working directory
WORKDIR /workspace
# Switch to non-root user
RUN chown -R node: /workspace
USER node
.devcontainer/devcontainer.json
{
"name": "Trading Platform Dev",
"dockerComposeFile": "../docker-compose.yml",
"service": "dev",
"workspaceFolder": "/workspace",
"customizations": {
"vscode": {
"extensions": [
"ms-vscode-remote.remote-containers",
"Prisma.prisma",
"esbenp.prettier-vscode",
"dbaumer.vscode-eslint",
"firsttris.vscode-jest-runner"
]
}
}
}