1

Macbook Pro M2 Max. Docker Desktop 4.20.1

This is the strangest thing, but perhaps someone can clarify what's happening for me. I'm running two different images, because I need two different versions of pg for two different projects. I use 13.3 for one, and 15.3 for the other. Here are my respective commands.

docker run --rm -v /Users/me/docker/postgres/13.3:/var/lib/postgresql/data -p 5432:5432 --name postgres-local-13 -e POSTGRES_PASSWORD=password1 -d postgres:13.3

This works fine...completed a project of two years, shut it down, and started a new one on 15.3:

docker run --rm -v /Users/me/docker/postgres/15.3:/var/lib/postgresql/data -p 5432:5432 --name postgres-local-15 -e POSTGRES_PASSWORD=password2 -d postgres:15.3

Here's the crazy thing - when running 15.3, I can't connect w/ "password2", but I can with "password1" - even though that instance isn't running. How is this possible?

I've verified in DBeaver and the sequelize cli - I have to use the password from the older image, which isn't even running, and doesn't share configuration with the one that IS running.

Tsar Bomba
  • 1,047
  • 6
  • 29
  • 52
  • 2
    The environment variables are only used when the database is first initialized. Both containers are using the same data directory, so the initialization phase doesn't run again and the old password is used. You'd see the same behavior if you changed the environment variable but used the same image. – David Maze Jul 03 '23 at 20:55
  • @DavidMaze I was under the impression that this was two different data directories, inside of two completely different containers. Aren't two different containers being created from two completely different images, here? – Tsar Bomba Jul 03 '23 at 20:57
  • Are you sure the 15.3 folder is totally empty before launching your container ? – Zeitounator Jul 03 '23 at 21:07
  • @Zeitounator No, neither folders are empty. I'm mapping local volumes so I can retain data between sessions. Also, due to SCRAM auth in newer pg, I have to manually configure pg_hba.conf or I can't authenticate at all. – Tsar Bomba Jul 03 '23 at 21:11
  • 1
    So as explained above (but for a different reason here), the password in env has no effect if the folder isn't empty. The database isn't initilialized and any previous password is used. The only logical explanation is that you have previously init that 15.3 db with the same pw as the 13.3 version. – Zeitounator Jul 03 '23 at 21:13
  • 1
    Not a strict duplicate but will give you more information: https://stackoverflow.com/questions/59838692/mysql-root-password-is-set-but-getting-access-denied-for-user-rootlocalhost/59839180#59839180 – Zeitounator Jul 03 '23 at 21:18
  • 1
    @Zeitounator Ah, OK...that makes more sense to me. If I had originally init'd the 15.3 container w/ "password1" and not cleared the local volume contents, then changed the password to "password2", then it wouldn't work. I'd need to start with a fresh folder for that volume, with the new password. Do I understand it correctly? – Tsar Bomba Jul 03 '23 at 21:18
  • 1
    Well in that case it is a strict duplicate of above :) And the answer is yes you understood correctly (as explained in the duplicate link) – Zeitounator Jul 03 '23 at 21:20
  • 1
    @Zeitounator Thanks! Not always easy to know what to search for. Appreciate the help and reference. – Tsar Bomba Jul 03 '23 at 21:24

0 Answers0