Can't connect to Postgres

I am unable to connect to Postgres inside a codespace and am trying to determine whether this is a bug or user error.

To minimize risk of user error, I copied the entire folder from https://github.com/microsoft/vscode-dev-containers/tree/master/containers/javascript-node-postgres into a repo of my own at https://github.com/andyweiss1982/codespace-node-postgres.

I can connect to the PG instance from inside VS Code Desktop, using the remote extension pack.

However, I can not replicate this from a codespace generated from the same repo, it looks like the DB may not be initializing properly. Below are the logs from SQL connection - any advice is greatly appreciated!

[1605024196090] INFO  (ext): SQLTools is starting
[1605024196095] INFO  (ext): initializing language client...
[1605024196096] INFO  (ext): Registering client for languages [{"scheme":"sqltools"},{"language":"sql","scheme":"untitled"},{"language":"sql","scheme":"file"},{"language":"sql","scheme":"sqltools"}]
    ns: "lc"
[1605024196102] INFO  (ext): loading plugins...
[1605024196102] INFO  (ext): registering Formatter Plugin.
    plugin: {
      "name": "Formatter Plugin"
    }
[1605024196102] INFO  (ext): registering Connection Manager Plugin.
    plugin: {
      "name": "Connection Manager Plugin"
    }
[1605024196103] INFO  (ext): registering CodeLens Plugin.
    plugin: {
      "name": "CodeLens Plugin",
      "registeredLanguages": []
    }
[1605024196104] INFO  (ext): registering Dependency Manager Plugin.
    plugin: {
      "name": "Dependency Manager Plugin",
      "installingDrivers": []
    }
[1605024196106] INFO  (ext): Connection explorer changed. Will be updated.
    ns: "conn-man:explorer"
[1605024196106] INFO  (ext): registering History Manager Plugin.
    plugin: {
      "name": "History Manager Plugin"
    }
[1605024196107] INFO  (ext): registering Bookmarks Manager Plugin.
    plugin: {
      "name": "Bookmarks Manager Plugin"
    }
[1605024196108] INFO  (ext): SQLTools activation completed. 18.018266 ms
[1605024196109] INFO  (ext): Formatter Plugin registered!
[1605024196109] INFO  (ext): CodeLens Plugin registered!
[1605024196109] INFO  (ext): Dependency Manager Plugin registered!
[1605024196109] INFO  (ext): Connection Manager Plugin registered!
[1605024196109] INFO  (ext): History Manager Plugin registered!
[1605024196109] INFO  (ext): Bookmarks Manager Plugin registered!
[1605024196313] INFO  (ls): SQLTools Server started!
===============================
Using node runtime?: no
ExecPath: /home/node/.vscode-remote/bin/fcac248b077b55bae4ba5bab613fd6e9156c2f0c/node 
===============================
[1605024196320] INFO  (ls): Telemetry enabled!
    ns: "telemetry"
[1605024196502] INFO  (ext): LanguageClient ready
    ns: "lc"
[1605024196589] INFO  (ext): registering PostgreSQL/Redshift Plugin (driver).
    plugin: {
      "extensionId": "mtxr.sqltools-driver-pg",
      "name": "PostgreSQL/Redshift Plugin",
      "type": "driver"
    }
[1605024196598] INFO  (ls): REQUEST RECEIVED => ls/RegisterPlugin
[1605024196598] INFO  (ls): request to register plugin: "/home/node/.vscode-remote/extensions/mtxr.sqltools-driver-pg-0.2.0/out/ls/plugin.js"
[1605024196660] INFO  (ls): Driver postgresql registered!
    place: "driver-map"
    ns: "ls-context"
[1605024196660] INFO  (ls): Driver aws redshift registered!
    place: "driver-map"
    ns: "ls-context"
[1605024196665] INFO  (ext): PostgreSQL/Redshift Plugin (driver) registered!
[1605024197683] INFO  (ext): EXECUTING COMMAND => sqltools.refreshTree
[1605024197684] INFO  (ext): Connection explorer changed. Will be updated.
    ns: "conn-man:explorer"
[1605024198107] INFO  (ext): Connection explorer changed. Will be updated.
    ns: "conn-man:explorer"
[1605024202594] INFO  (ext): EXECUTING COMMAND => sqltools.getConnections
[1605024202595] INFO  (ls): REQUEST RECEIVED => connection/GetConnectionsRequest
[1605024204480] INFO  (ext): EXECUTING COMMAND => sqltools.selectConnection
[1605024204480] INFO  (ext): EXECUTING COMMAND => sqltools.getConnections
[1605024204481] INFO  (ls): REQUEST RECEIVED => connection/GetConnectionsRequest
[1605024204482] INFO  (ext): EXECUTING COMMAND => sqltools.getConnections
[1605024204482] INFO  (ls): REQUEST RECEIVED => connection/GetConnectionsRequest
[1605024204483] INFO  (ls): REQUEST RECEIVED => connection/ConnectRequest
[1605024204484] INFO  (ls): Connection instance created for Container database.
    ns: "conn-manager"
[1605024204493] ERROR (ls): Connecting error: {"code":-32001,"data":{"driver":"PostgreSQL","driverOptions":{}},"name":"Error"}
    ns: "conn-manager"
[1605024204495] ERROR (ext): ERROR: Error opening connection connect ECONNREFUSED 127.0.0.1:5432, {"code":-32001,"data":{"driver":"PostgreSQL","driverOptions":{}}}
    ns: "error-handler"
[1605024208279] INFO  (ext): EXECUTING COMMAND => sqltools.showOutputChannel

HI @andyweiss1982, Codespaces currently forces host networking mode for the main container (although we’re working on removing this requirement for Docker Compose over the next few weeks). The simplest solution for now would be to alter Your db service at https://github.com/andyweiss1982/codespace-node-postgres/blob/9ba9a5647b6988e8ad41b0df0fbf28c6ca78a6b9/.devcontainer/docker-compose.yml#L30 to have network_mode: host. Then the main Codespace container will be able to see the DB container’s ports. Hope that helps!

Worked like a charm, thank you!

By any chance is there an issue or doc page I can watch to follow progress on this or learn more?

I love the direction this project is going in and can’t wait to use in an educational setting.