0

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?

3
  • 1
    Because that is the way it is supposed to be. See here postgres image and read the section POSTGRES_USER. Commented Dec 29, 2021 at 0:36
  • Do you mean that it creates a database user called 'postgres,' or a Linux user called 'postgres'? To my knowledge, the POSTGRES_USER variable only controls the first thing, and there isn't a way to control the second thing in the official Docker image. Commented Dec 29, 2021 at 0:36
  • It seems like you probably shouldn't need docker exec at all here. "Get a shell inside a database" doesn't seem like an ordinary use case, and if you do it shouldn't matter what Linux user you are so long as the filesystem permissions match up. I wouldn't worry about this use case, and just connect to the database with psql or a language-native client library. Commented Dec 29, 2021 at 11:58

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.