Issue with mounting servers.json into pgadmin container

@rimelek I tried to bind servers.json from host into my docker container but it seems something is preventing that from happening. I even tried to change its ownership thinking that might be the culprit like this sudo chown -R 5050:5050 servers.json but that did not work either. Here is what I did:

compose.yml:

services:
  postgres:
    image: postgres:17.0-alpine3.20
    restart: always
    ports:
      - "${POSTGRESQL_EXPOSED_PORT}:5432"
    volumes:
      - /data/postgres:/data/postgres
    env_file:
      - .env
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 5s
      timeout: 5s
      retries: 5

  pgAdmin:
    image: dpage/pgadmin4:8.1
    restart: always
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: admin
    ports:
      - "${PGADMIN_EXPOSED_PORT}:80"
    volumes:
      - ./servers.json:/tmp/servers.json

.env

PGADMIN_EXPOSED_PORT=5050
POSTGRESQL_EXPOSED_PORT=5432
PGUSER=username
POSTGRES_DB=db-name
POSTGRES_USER=username
POSTGRES_PASSWORD=change-me
COMPOSE_PROJECT_NAME=postgre_pgadmin
PGDATA=/var/lib/postgresql/data/pgdata

servers.json

{
  "Servers": {
    "1": {
      "Name": "postgres",
      "Group": "GroupName",
      "Port": 5432,
      "Username": "username",
      "Host": "localhost",
      "SSLMode": "prefer",
      "MaintenanceDB": "db-name",
      "BGColor": "#1f1f1f",
      "FGColor": "#000000",
      "Comment": "This server will connect to the instance we've created in our compose file."
    }
  }
}

Can you see anything wrong with this setup? Personally failed to diagnose it so I just for now decided to go with something like this: docker/docker-compose-files/postgres/postgres-pgadmin/compose.yml at main · kasir-barati/docker · GitHub

BTW if my repo was helpful consider giving it a star

I moved your post into a separate topic as the other topic was 2 years old discussing a bigger issue and it seems you only have problem with mounting a file. Although you forgot to mention what error message you got and what the result was. Maybe I miss something, but until I understand what your issue, I would not look at source code.

So what happened? Were you able to mount a file? Have you checked it from inside the container (I don’t remember if that container has a shell or not)? Was the folde rmounted as a folder? Did you get an error message? If you got, what was it?

what happened?

File was not mounted.

Were you able to mount a file?

Nope.

Have you checked it from inside the container?

Yes, and to my shock it was not mapped at all. BTW it has sh and not bash.

Was the folder mounted as a folder?

No, I was mapping each file separately.

But when I used this compose file it worked. I mean it is literally creating it (ref for docker configs):

service:
  # ...
  pgAdmin:
    image: dpage/pgadmin4:8.1
    restart: always
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: admin
    ports:
      - ${PGADMIN_EXPOSED_PORT}:80
    configs:
      - source: servers.json
        target: /pgadmin4/servers.json
      - source: preferences.json
        target: /pgadmin4/preferences.json

configs:
  preferences.json:
    content: |
      {
        "preferences": {
          "misc:themes:theme": "dark",
          "browser:display:show_system_objects": true,
          "browser:display:confirm_on_refresh_close": false,
          "browser:display:show_user_defined_templates": true
        }
      }
  servers.json:
    content: |
      {
        "Servers": {
          "1": {
            "Group": "Servers",
            "Name": "Database name",
            "Host": "postgres",
            "Port": 5432,
            "MaintenanceDB": "${POSTGRES_DB}",
            "Username": "${POSTGRES_USER}",
            "SSLMode": "prefer",
            "BGColor": "#FF4500",
            "FGColor": "#222222",
            "Comment": "This server will connect to the instance we've created in our compose file."
          }
        }
      }

Did you get an error message?

No error message.