I’m trying to create a postgres container, I have the following in my Docker Compose:

db:
  container_name: db
  image: postgres
  restart: always
  environment:
    #POSTGRES_USER="postgres"
    POSTGRES_PASSWORD: HDFnWzVZ5bGI
  ports:
    - 5432:5432
  volumes:
    - pgdata:/var/lib/postgresql/data
adminer:
  container_name: adminer
  image: adminer
  restart: always
  ports:
    - 8338:8080

And yet Docker keeps saying that the database is initialized and that the superuser is not specified. Where am I going wrong?

I’ve tried with and without equals, a hyphen, quotation marks. No matter what I try, it won’t see it.

#Solution:

Find:

  volumes:
    - pgdata:/var/lib/postgresql/data

Replace:

  volumes:
    - /opt/postgres/data:/var/lib/postgresql/data

More info: https://lazysoci.al/comment/8597610

  • rolaulten@startrek.website
    link
    fedilink
    arrow-up
    3
    ·
    8 months ago

    As others have said, remove the # to uncommit the line.

    Commits are a special type of line in many languages that allow us humans to stick info (generally for humans) inside the code that the interpreter skips over. From the machines perspective this block looks like:

    environment:
        POSTGRES_PASSWORD: HDFnWzVZ5bGI
    

    Note that the entire line is missing.

    As a side note. Please change the password as it’s been posted to the Internet.

    • sabreW4K3OP
      link
      fedilink
      arrow-up
      1
      ·
      8 months ago

      Thanks, I tried with and without the POSTGRES_USER line commented out, still not joy. The documentation says it should default to default when not declared.

      As for the password, don’t worry I changed it right away.

      • rolaulten@startrek.website
        link
        fedilink
        arrow-up
        2
        ·
        8 months ago

        I assume there is nothing in the database? Delete the file under volumes and relaunch. At a guess your database for initialized without a user and is now just in that state.