Home > Software design >  Why isn't Docker Compose honoring my POSTGRES_USER environment variable?
Why isn't Docker Compose honoring my POSTGRES_USER environment variable?

Time:12-29

I know lots of questions sound like this, and they all have the same answer: delete your volumes to force it to reinitialize.

The problem is, I'm being careful to delete my volumes, but it's consistently spinning up the container incorrectly every time.

My docker-compose.yml

version: "3.1"
services:
  db:
    environment:
      - POSTGRES_DB=mydb
      - POSTGRES_PASSWORD=changeme
      - POSTGRES_USER=myuser
    image: postgres

My process:

$ docker volume ls
DRIVER   VOLUME NAME
$ docker-compose up -v # or docker-compose up --force-recreate

yet it always creates the "postgres" user instead of myuser. The output when it starts up shows that it "will be owned by user 'postgres'" and I can only docker exec as postgres, not my user.

The instructions seem very straightforward. Am I missing something, or is this a bug?

What happens when you use the compose file above?

CodePudding user response:

I can only docker exec as postgres, not myuser

The environment variable POSTGRES_USER controls the database user, not the linux user. Take a look at the chapter Arbitrary --user Notes in the documentation to learn how to change the linux user.

  • Related