-1

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"
            ]
        }
    }
}
2
  • You can try to delete your container manually with "docker system prune -a" (deleted all the docker container) or with "docker rm ID_or_Name ID_or_Name" (delete the container). But, in your docker-compose file, you have your db setup on "restart: no" . Try with "restart:yes". Commented Oct 18 at 18:34
  • I tried that. But it doesn't matter what i set at restart var. I ended up using different image (not a alpine image). now it works Commented Oct 18 at 20:58

1 Answer 1

0

I ended up fixing this problem by staying away from postgres:17-alpine. Instead just used postgres:17 image and everything works fine now.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm think that it's better use postgres:lastest because the upgrade are added ! Except when your database depends on a system who required a specific version. But, it's good if that's work now !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.