Can't connect to databases from devcontainer

Viewed 335

I'm working on building an environment for an educational setting, but for some reason my dev container isn't able to connect to the databases that are being generated by the docker-compose.yml. See below:

# docker-compose.yml
version: '3.9'

services:
  conda:
    image: continuumio/anaconda3:latest
    build:
      context: ..
      dockerfile: .devcontainer/Dockerfile
    command: sleep infinity
    volumes:
      - ..:/workspace:cached

  mongo:
    image: mongo:latest
    restart: unless-stopped
    volumes:
      - dbs:/data/db

  postgres:
    image: postgres:latest
    restart: unless-stopped
    volumes:
      - dbs:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: postgres
  
volumes:
  dbs:

When I attempt to connect to the PostgreSQL database using SQLTools on port 5432 on localhost, I get the following:

[1642491269885] ERROR (ls): Connecting error: {"code":-32001,"data":{"driver":"PostgreSQL","driverOptions":{}},"name":"Error"}
    ns: "conn-manager"
[1642491269886] ERROR (ext): ERROR: Error opening connection connect ECONNREFUSED 127.0.0.1:5432, {"code":-32001,"data":{"driver":"PostgreSQL","driverOptions":{}}}
    ns: "error-handler"

As a possibly important aside, I am also noticing that the PostgreSQL instance is constantly restarting. Here is what the docker container set looks like:

enter image description here

However, I should note that I can't connect to the mongodb instance either, using the Mongo for VS Code extension.

Let me know how I can make this work!

0 Answers
Related