0

Hello i need some help im using TablePlus to connect to my database but this isn't working with adding the forwardPorts devcontainer.json

    {
        "name": "Node.js & PostgreSQL",
        "dockerComposeFile": "docker-compose.yml",
        "service": "app",
        "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
          "forwardPorts": [5432]
    }

docker-compose.yml

version: '3.8'
services:
    app:
        build:
            context: .
            dockerfile: Dockerfile
        volumes:
            - ../..:/workspaces:cached
        # Overrides default command so things don't shut down after the process ends.
        command: sleep infinity
        # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
        network_mode: service:db
        # Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
        # (Adding the "ports" property to this file will not forward from a Codespace.)
    db:
        image: postgres:latest
        restart: unless-stopped
        volumes:
            - postgres-data:/var/lib/postgresql/data
        environment:
            POSTGRES_PASSWORD: postgres
            POSTGRES_USER: postgres
            POSTGRES_DB: postgres
        # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
        # (Adding the "ports" property to this file will not forward from a Codespace.)
volumes:
    postgres-data:

Dockerfile

FROM mcr.microsoft.com/devcontainers/javascript-node:0-18

I already add forwardPorts in devcontainer.json and port in docker-compose.yml this doesn't change something

damlam
  • 1

1 Answers1

1

According to the documentation for devcontainer.json, you have to specify the container name together with the port, when using docker compose and you want to forward a port from a container which is not the primary container.

The line in your devcontainer.json should be:

"forwardPorts": ["db:5432"]
MSpiller
  • 3,500
  • 2
  • 12
  • 24