brainoverflow
brainoverflow

Reputation: 745

how to change Postgresql docker image password

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?

Upvotes: 7

Views: 33451

Answers (2)

lastlink
lastlink

Reputation: 1745

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';

Upvotes: 5

msrc
msrc

Reputation: 785

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.

Upvotes: 21

Related Questions