Postgresql password change

I am writing own custom Dockerfile, I am not able to change the postgres user passwd

Last line of the Dockerfile.

CMD ["/"] contains

su - postgres -c '/usr/pgsql-9.3/bin/postgres -D /pg_home’
su - postgres -c “psql -U postgres -c “alter user postgres with password ‘postgres1234’;””

I am able to build the image container is getting started, but passwd is not getting changed.

If you can use the official postgres image, or base your image on it, you can pass in a username and password as an environment variable when you docker run it. Like so:

docker run -it -e POSTGRES_PASSWORD=some_password postgres:9.4

You can also pass in POSTGRES_USER, POSTGRES_DB, and PGDATA, which is a file location where the database should store the data files.