Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python &引用;psql:fe_sendauth:未提供密码;将postgres作为Docker服务运行时_Python_Bash_Postgresql_Docker - Fatal编程技术网

Python &引用;psql:fe_sendauth:未提供密码;将postgres作为Docker服务运行时

Python &引用;psql:fe_sendauth:未提供密码;将postgres作为Docker服务运行时,python,bash,postgresql,docker,Python,Bash,Postgresql,Docker,我正在尝试使用以下Docker Compose.yml运行以下Docker Compose多容器应用程序: version: '3' services: postgres: image: postgres environment: - POSTGRES_USER=iperuser - POSTGRES_PASSWORD=iperpassword - PGDATA=/var/lib/postgresql/data/apks -

我正在尝试使用以下
Docker Compose.yml
运行以下Docker Compose多容器应用程序:

version: '3'

services:
  postgres:
    image: postgres
    environment:
      - POSTGRES_USER=iperuser
      - POSTGRES_PASSWORD=iperpassword
      - PGDATA=/var/lib/postgresql/data/apks
      - POSTGRES_DB=iper_apks

  alchemy:
    build: ./alchemy
    environment:
      - PGHOST=postgres
      - PGPORT=5432
      - PGUSER=iperuser
    links:
      - postgres
我想使用
wait for postgres.sh
脚本,让
alchemy
服务等待
postgres
准备好接受命令:

alchemy
服务的
Dockerfile

FROM python
RUN apt-get update && apt-get install --assume-yes postgresql
RUN pip install sqlalchemy psycopg2
COPY . /alchemy
WORKDIR alchemy
RUN chmod +x wait-for-postgres.sh
CMD ["./wait-for-postgres.sh", "postgres", "python", "apk_tables.py"]
其中我使用的是主机名
postgres
,因为这是与
postgres
Docker映像对应的服务的名称。问题是,如果我
docker compose build
后跟
docker compose up
,我会得到以下日志:

Starting apkapi_postgres_1
Recreating apkapi_alchemy_1
Attaching to apkapi_postgres_1, apkapi_alchemy_1
postgres_1  | LOG:  database system was shut down at 2017-06-26 17:22:32 UTC
alchemy_1   | Password for user postgres: 
postgres_1  | LOG:  MultiXact member wraparound protections are now enabled
alchemy_1   | psql: fe_sendauth: no password supplied
postgres_1  | LOG:  database system is ready to accept connections
alchemy_1   | Postgres is unavailable - sleeping
postgres_1  | LOG:  autovacuum launcher started
alchemy_1   | Password for user postgres: 
alchemy_1   | psql: fe_sendauth: no password supplied
alchemy_1   | Postgres is unavailable - sleeping
alchemy_1   | Password for user postgres: 
alchemy_1   | psql: fe_sendauth: no password supplied
alchemy_1   | Postgres is unavailable - sleeping
这将永远持续下去


我怀疑的是
wait for postgres.sh
假设PostgreSQL在本地主机上运行,该主机是可信的,而在其他主机上运行的数据库需要密码。是这样吗?如果是这样,我如何修改脚本以使其使用密码(在本例中,我假设密码是
iperpassword
)?

看起来您只需将密码传递到
psql
命令中,它就能够显示远程主机所需的密码。下面的问题给出了实现这一点的选项:

是的,最后我在
炼金术
服务的
环境
中添加了
PGPASSWORD=iperpassword
行。
Starting apkapi_postgres_1
Recreating apkapi_alchemy_1
Attaching to apkapi_postgres_1, apkapi_alchemy_1
postgres_1  | LOG:  database system was shut down at 2017-06-26 17:22:32 UTC
alchemy_1   | Password for user postgres: 
postgres_1  | LOG:  MultiXact member wraparound protections are now enabled
alchemy_1   | psql: fe_sendauth: no password supplied
postgres_1  | LOG:  database system is ready to accept connections
alchemy_1   | Postgres is unavailable - sleeping
postgres_1  | LOG:  autovacuum launcher started
alchemy_1   | Password for user postgres: 
alchemy_1   | psql: fe_sendauth: no password supplied
alchemy_1   | Postgres is unavailable - sleeping
alchemy_1   | Password for user postgres: 
alchemy_1   | psql: fe_sendauth: no password supplied
alchemy_1   | Postgres is unavailable - sleeping