Resolve Postgres error uninitialized using docker

Resolve Postgres  error uninitialized using docker

👉 Error: Database is uninitialized and superuser password is not specified.

💡
A error is something it comes when we try to run docker compose build for Postgres Database

How is this coming along?

When you are executing docker build compose for Postgres database, and when you run the database, container id will get create but it will get exited immediately due to password not specified.

How do you identify yourself and why?

docker container logs container_id

What is the approach in solving this issue?

So this was a recent change in the Postgres database image that makes it necessary to specify a default superuser password as such database is not initialized we fix by specify environment variable.

To avoid that you can specify the followings environments variables for postgres container on your docker-compose file.

  1. Allow all connections without a password use:

    💡
    Postgres explicitly states this is not recommended.
docker run -e POSTGRES_HOST_AUTH_METHOD=trust postgres:15-alpine (use the tag you need).
  1. To specify Postgres password for the superuser, use:
docker run -e POSTGRES_PASSWORD=<your_password> postgres:15-alpine (use the tag you need)

If you liked what you read, do follow and any feedback for further improvement will be highly appreciated!

Thank you and Happy Learning!👏