"role "postgres" does not exist" - installing Label Studio with Postgres and Docker compose -

Hello,

I am trying to install Label Studio (latest image, v1.12.1, presumably) with Postgres (v16 alpine), using Docker compose.

I have read this guide and also saw this example docker compose file.

I don’t necessarily need that version of Postgres, but figured I may as well use a reasonably-modern version. I note that the example compose file used v11.5; I tried that but had the same issue.

Specifically when I run docker compose up, I see this error in the Postgres logs: 2024-07-27 07:53:33.374 UTC [335] FATAL: role "postgres" does not exist

And similar in the Label Studio logs: django.db.utils.OperationalError: connection to server at "Postgres-LabelStudio" (172.22.0.22), port 5432 failed: FATAL: role "postgres" does not exist

Earlier today, I did try using the default configuration (without Postgres), and was able to get that to load and saw the user sign-up screen. It’s just getting it working with Postgres that I’m having problems with.

I was previously seeing a permission error, but found this and ran the command: docker run -it --user root -v pwd/mydata:/label-studio/data heartexlabs/label-studio:1.7.0 chown -R 1001:root /label-studio/data/ - that seemed to fix the permission issue.

I have previously installed Postgres for a completely different Docker service (Authentik SSO). I was not sure if changing the container_name would be sufficient to have two separate instances of Postgres (one for Authentik, one for Label Studio). While I have installed it for Authentik, I’ll be honest in saying I don’t really understand what I’ve done, so I may be doing all this the wrong way.

I also remember when I installed Postgres for Authentik, if I had files existing in certain folders, it wouldn’t create the new database for Authentik.
Are there any specific folders that should be empty when I try to docker compose up my Label Studio compose.yml file?

I am including my docker-compose.yml file below. Could anyone suggest what I might be doing incorrectly please?

Thank you in advance.
Dave

Contents of /home/david/dockerfilesNotOnNAS/labelstudio/dockercompose-labelstudio.yml:

services:
  label-studio:
    container_name: LabelStudio
    image: heartexlabs/label-studio:latest
    networks:
      - proxy
    # environment:
    #   - PUID = 1000
    #   - PGID = 1000
    # user: root
    # ports:
    #   - 8090:8080
    volumes:
    - /home/david/dockerfilesNotOnNAS/labelstudio/mydata:/label-studio/data:rw
    - source: static
      target: /label-studio/static_volume
      type: volume
      volume:
        nocopy: true
    restart: unless-stopped
    dns: 172.22.0.53
    environment:
      - DJANGO_DB=default
      - POSTGRE_NAME=postgres
      - POSTGRE_USER=postgres
      - POSTGRE_PASSWORD=
      - POSTGRE_PORT=5432
      - POSTGRE_HOST=Postgres-LabelStudio
      - LABEL_STUDIO_HOST=${LABEL_STUDIO_HOST:-}
      - LABEL_STUDIO_COPY_STATIC_DATA=true
    depends_on:
      - Postgres-LabelStudio
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.label-studio.entrypoints=http"
      - "traefik.http.routers.label-studio.rule=Host(`label-studio.mydomain.com`)"
      - "traefik.http.routers.label-studio.middlewares=default-whitelist@file"
      - "traefik.http.middlewares.label-studio-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.label-studio.middlewares=label-studio-https-redirect"
      - "traefik.http.routers.label-studio-secure.entrypoints=https"
      - "traefik.http.routers.label-studio-secure.rule=Host(`label-studio.mydomain.com`)"
      - "traefik.http.routers.label-studio-secure.tls=true"
      - "traefik.http.routers.label-studio-secure.service=label-studio"
      - "traefik.http.services.label-studio.loadbalancer.server.port=8080"
      - "traefik.docker.network=proxy"
      - homepage.group=Machine Learning
      - homepage.name=Label Studio
      - homepage.icon=https://ia801409.us.archive.org/31/items/github.com-heartexlabs-label-studio_-_2022-08-05_01-43-27/cover.jpg
      - homepage.href=https://label-studio.mydomain.com/
      - homepage.description=Data and image labelling for machine learning applications.
      - homepage.statusStyle=dot
  Postgres-LabelStudio:
    image: docker.io/library/postgres:16-alpine
    container_name: Postgres-LabelStudio
    hostname: Postgres-LabelStudio
    restart: always
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
      start_period: 20s
      interval: 30s
      retries: 5
      timeout: 5s
    dns: 172.22.0.53
    env_file:
      - .env
    networks:
      - proxy
    environment:
      - POSTGRES_HOST_AUTH_METHOD=trust
      - POSTGRES_USER=${PG_USER}
      - POSTGRES_PASSWORD=${PG_PASS}
      - POSTGRES_DB=${PG_DB}
    volumes:
      - /home/david/dockerfilesNotOnNAS/labelstudio/postgres-data:/var/lib/postgresql/data
      - ./deploy/pgsql/certs:/var/lib/postgresql/certs:ro
    
networks:
  proxy:
    external: true

volumes:
  static: {}

…and contents of /home/david/dockerfilesNotOnNAS/labelstudio/.env:

PG_PASS=longpasswordhere
PG_USER=labelstudioDBuser
PG_DB=LabelStudioDB

Got it working with help from the Postgres maintainer.

Here’s what I ended up with, in case it helps someone else in future:

environment:
      - DJANGO_DB=default
      - POSTGRE_NAME=postgres
      - POSTGRE_USER=${PG_USER}
      - POSTGRE_PASSWORD=${PG_PASS}
      - POSTGRE_PORT=5432
      - POSTGRE_HOST=Postgres-LabelStudio
      - LABEL_STUDIO_HOST=${LABEL_STUDIO_HOST:-}
      - LABEL_STUDIO_COPY_STATIC_DATA=true
environment:
      - POSTGRES_HOST_AUTH_METHOD=false
      - POSTGRES_USER=${PG_USER}
      - POSTGRES_PASSWORD=${PG_PASS}
      - POSTGRES_DB=${PG_DB}

The problem was that I had the user and password set to “postgres” within the Label Studio section, and set to the variable PG_USER or PG_PASS in the Postgres section. I didn’t understand that these referred to the same thing and so should be set to the same thing.