Where is the Postgres username/password being created in this Dockerfile?

Not sure which postgres image are you using.

If you look at the official postgres image for complete information. It allows user to specify the environment variables for the below ones and these can be easily overridden at run time.

  • POSTGRES_PASSWORD
  • POSTGRES_USER
  • PGDATA
  • POSTGRES_DB
  • POSTGRES_INITDB_ARGS

Environment variables can be overridden using below three methods depending on your case.

  • Run Image: If running docker image directly, use below to include environment variable in docker run with -e K=V. Please refer documentation for more details here
docker run -e POSTGRES_PASSWORD=secrect -e POSTGRES_USER=postgres <other options> image/name
  • Dockerfile: If you need to specify the environment variable in Dockerfile, specify as mentioned below. Please refer documentation for more details here
ENV POSTGRES_PASSWORD=secrect
ENV POSTGRES_USER=postgres
  • docker-compose: If you need to specify the environment variable in docker-compose.yml, specify as below. Please refer documentation for more details here
web:
  environment:
    - POSTGRES_PASSWORD=secrect
    - POSTGRES_USER=postgres

Hope this is useful.

Leave a Comment