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

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

问题描述

您好,我在运行 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.

这是错误的快照!

下面是我的 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天全站免登陆