如何解决错误“错误:数据库未初始化,并且未指定超级用户密码。” [英] How to fix error "Error: Database is uninitialized and superuser password is not specified."

查看:753
本文介绍了如何解决错误“错误:数据库未初始化,并且未指定超级用户密码。”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在运行docker-compose build up后收到此错误

Hello i get this error after i run docker-compose build up

但是我收到此错误
postgres_1 |错误:数据库尚未初始化,并且未指定超级用户密码。

But i get this error postgres_1 | Error: Database is uninitialized and superuser password is not specified.

这里是错误的快照!

Here is a snap shot of the error!

下面是我的docker-compose.yml文件

And down below is my docker-compose.yml file

版本:'3.6'

services: 
  smart-brain-api:
    container_name: backend
    build: ./
    command: npm start
    working_dir: /usr/src/smart-brain-api
    ports:
      - "3000:3000"
    volumes:
      - ./:/usr/src/smart-brain-api
 
  #PostGres Database
 
  postgres:
    image: postgres
    ports:
      - "5432:5432"


推荐答案

为避免这种情况,您可以指定以下环境变量docker-compose文件上的postgres容器。

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

POSTGRES_PASSWORD
使用PostgreSQL映像通常需要此环境变量。此环境变量设置PostgreSQL的超级用户密码。默认的超级用户由POSTGRES_USER环境变量定义。

POSTGRES_PASSWORD This environment variable is normally required for you to use the PostgreSQL image. This environment variable sets the superuser password for PostgreSQL. The default superuser is defined by the POSTGRES_USER environment variable.

POSTGRES_DB
此可选的环境变量可用于定义其他名称。用于首次启动映像时创建的默认数据库。如果未指定,则将使用POSTGRES_USER的值。

POSTGRES_DB This optional environment variable can be used to define a different name for the default database that is created when the image is first started. If it is not specified, then the value of POSTGRES_USER will be used.

有关环境变量的更多信息,请检查:
https://hub.docker.com/_/postgres

For more information about Environment Variables check: https://hub.docker.com/_/postgres

这篇关于如何解决错误“错误:数据库未初始化,并且未指定超级用户密码。”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆