0

My intention is to build a .devcontainer with 3 services. One is a ASP.NET app, another one is PostgreSQL and finally another one with PGAdmin as I want to have access to the DB during development.

My issues is that I can't bind to the servers.json file to pre-configure pgadmin lists of servers. No matter what I do, servers.json file is not found and a folder is created within the pgadmin container.

Here is my config, let's start with the folder structure:

.devcontainer/
├─ devcontainer.json
├─ docker-compose.yaml
├─ Dockerfile
├─ servers.json

This is the content of my devcontainer.json file:

{
    "name": "endoftime",
    "dockerComposeFile" : "docker-compose.yaml",
    "service": "app",
    "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
    "shutdownAction": "none",
    "customizations": {
        "vscode": {
            "settings": {},
            "extensions": [
                "ms-azuretools.vscode-docker",
                "mhutchie.git-graph",
                "bradlc.vscode-tailwindcss",
                "esbenp.prettier-vscode",
                "csstools.postcss",
                "PKief.material-icon-theme",
                "ms-vscode.vscode-typescript-next",
                "dbaeumer.vscode-eslint"
            ]
        }
    }
}

This is my docker-compose.yaml file:

version: '3.9'

services:
  postgres:
    container_name: postgres_container
    image: postgres:15.3
    restart: unless-stopped
    environment:
      POSTGRES_USER: 'admin'
      POSTGRES_PASSWORD: 'endoftime'
      POSTGRES_DB: 'main'
    expose:
      - 5432
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
      interval: 10s
      timeout: 5s
      retries: 5
    volumes:
      - postgres_data:/var/lib/postgresql/data

  pgadmin:
    container_name: pgadmin_container
    image: dpage/pgadmin4:7.1
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: 'admin@admin.com'
      PGADMIN_DEFAULT_PASSWORD: 'endoftime'
    ports:
      - "5050:80"
    volumes:
      - pgadmin_data:/var/lib/pgadmin
      - ./servers.json:/pgadmin4/servers.json
    depends_on:
      - postgres

  app:
    container_name: app_container
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ../..:/workspaces:cached
    command: sleep infinity
    depends_on:
      - postgres

volumes:
  postgres_data:
  pgadmin_data:

My Dockerfile:

FROM mcr.microsoft.com/devcontainers/dotnet:0-7.0

Finally, my servers.json file

{
    "Servers": {
        "1": {
            "Name": "end of time",
            "Group": "Servers",
            "Port": 5432,
            "Username": "admin",
            "Host": "postgres_container",
            "SSLMode": "prefer",
            "MaintenanceDB": "postgres"
        }
    }
}

Now, my code is not on my Windows machine. I have directly cloned the repository using the VSCode option: >dev Containers: Clone Repository in Container Volume... so there is no overload between Windows -> WSL -> Docker Container

The containers are created correctly as seen here: enter image description here

Yet the ./servers.json bind in the pgadmin server is not created correctly as the ./servers.json file 'is not found' and thus a folder is created instead of attaching the file.

volumes:
   - pgadmin_data:/var/lib/pgadmin
   - ./servers.json:/pgadmin4/servers.json

enter image description here

How can I properly bind this ./servers.json file to my pgadmin container through vscode devcontainers? Any help is kindly appreciated!

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
alFadorMX
  • 85
  • 8

0 Answers0