0

I have vps server on Ubuntu 20.04. Please help me with this, i'm stuck with it, i'm starting my application with postgresql db with docker compose and get this error, what i'm doing wrong?

error screenshot

My docker-compose.yml

version: '3.8'

x-restart-policy: &restart_policy
  restart: unless-stopped

services:
  discord-bot:
    << : *restart_policy
    depends_on: 
      - "postgres"
    container_name: discord-bot
    build:
      context: .
      dockerfile: DiscordBot.Application/Dockerfile
    environment: 
      - ENVIRONMENT=Release
    volumes: 
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro

  postgres:
      << : *restart_policy
      image: postgres:latest
      container_name: discordBot-db
      env_file: .env
      healthcheck:
        test: ["CMD-SHELL", "pg_isready"]
        interval: 10s
        timeout: 5s
        retries: 5
      command: ["-c", "shared_buffers=512MB", "-c", "max_connections=500"]
      expose:
        - '5432'
      ports:
        - '5432:5432'
      volumes:
        - ./dockervolumes/postgress/srv/postgresql/data:/var/lib/postgresql/data

My env file:

POSTGRES_HOST_AUTH_METHOD=trust
POSTGRES_DB=My_dbname
POSTGRES_USER=postgres
POSRGRES_PASSWORD=my_pass

What i'm doing wrong?

Jack
  • 35
  • 2
  • 7
  • Poss dupe: https://stackoverflow.com/questions/60193781/postgres-with-docker-compose-gives-fatal-role-root-does-not-exist-error – Steve Wong Jan 07 '22 at 15:49
  • Can you post the connection string you use for the database connection? – Hans Kilian Jan 07 '22 at 17:07
  • var password = configuration["POSTGRES_PASSWORD"] ?? string.Empty; var dbName = configuration["POSTGRES_DB"] ?? string.Empty; var dbUser = configuration["POSTGRES_USER"] ?? string.Empty; var connectionString = "User ID = postgres;Password={password};Server=postgres;Port=5432;Database={dbName};Integrated Security=true;Pooling=true"; – Jack Jan 07 '22 at 20:32

1 Answers1

0
 postgres:
      << : *restart_policy
      image: postgres:latest
      container_name: discordBot-db
      user: postgres <-- Added this to service !!!
      env_file: .env
      healthcheck:
        test: ["CMD-SHELL", "pg_isready"]
        interval: 10s
        timeout: 5s
        retries: 5
      command: ["-c", "shared_buffers=512MB", "-c", "max_connections=500"]
      expose:
        - '5432'
      ports:
        - '5432:5432'
      volumes:
        - ./dockervolumes/postgress/srv/postgresql/data:/var/lib/postgresql/data

And run docker-compose up -d (to running in background) After this I've connected to db: docker exec -it postgres psql -U skaarl(which indicated in .env file) SkaarlDb(which indicated in .env file)

after I created postgres user and altered it as super user, after I've done docker-compose down and docker-compose up

And it works!

Jack
  • 35
  • 2
  • 7