7

I have created a Postgresql docker image using the following command on Windows:

docker run --name airdb-postgres -e POSTGRES_PASSWORD=post1234 -d -p 5432:5432 postgres:alpine

is it possible to change the password I assigned to it, or I should create a new one by disposing this image?

2
  • 1
    Name of the environment variable is PGPASSWORD not POSTGRES_PASSWORD (of course provided that there is already a user with this password). However can you please elaborate on what exactly you are trying to do? Commented Oct 31, 2019 at 13:02
  • I wasn't sure how it is possible to change the password of a postgresql docker image. I realized I can do it after logging into the container @mic4ael . Commented Oct 31, 2019 at 14:30

2 Answers 2

21

You should be able to do that by logging into the container

docker exec -it <container_id> bash

then use psql cli to change the password.

See How to change PostgreSQL user password? for the latter part.

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

3 Comments

I get: > psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "root" does not exist
@NessDan what command gave you that error?
@NessDan By default, it will log you in as a the user you are using if you do not have any arguments specified. Which, if you connect to the database using the docker exec command, will be root. You can specify the database name and the username within the psql command. Example: psql mydatabase myuser. See psql --help for more information about the command.
5

When I was upgrading postgres 12 to 15 for some reason my user passwords weren't working after the backup and restore. I was able to change fix it by doing the following. On windows I used git bash to run these commands.

bash

cat reset_password.sql | docker exec -i your-db-container-id psql -U postgres

reset_password.sql

ALTER USER postgres WITH PASSWORD 'mysecretpassword';

ALTER USER oc_admin WITH PASSWORD 'mysecretpassword';

2 Comments

Just as extra info: your problem was likely caused by the change in default password encryption from md5 to scram-sha-256 dbod-user-guide.web.cern.ch/instance_management/…
Thanks worked for me, just had to change postgres to my user.

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.