栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Docker

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Docker

您收到的身份验证错误将有很大帮助!

我用您的参数启动了postgres图像:

docker run --name db -d -e POSTGRES_PASSWORD=docker -e POSTGRES_USER=docker postgres

然后我执行了:

docker exec -it db psql -U docker userpsql: FATAL:  database "user" does not exist

我收到您期望的错误消息,因为我具有信任身份验证:

docker exec -it db cat /var/lib/postgresql/data/pg_hba.conf | grep -v '^#'local   all  all    trusthost    all  all  127.0.0.1/32 trusthost    all  all  ::1/128      trusthost all all 0.0.0.0/0 md5

为了模拟您的Web容器,我将运行postgres容器的另一个实例并链接db容器,然后再连接回db容器:

core@ku1 /tmp/i $ docker run --rm --name web --link db:db -it postgres psql -h db -Udocker userPassword for user docker: psql: FATAL:  password authentication failed for user "docker"

如果输入了错误的密码,则会收到身份验证错误。但是,如果我输入正确的密码:

core@ku1 /tmp/i $ docker run --rm --name web --link db:db -it postgres psql -h db -Udocker userPassword for user docker: psql: FATAL:  database "user" does not exist

一切似乎都正常工作。我将它们全部放入yaml文件中,并进行了同样的测试:

web:  image: postgres  command: sleep 999  ports:    - "62576:62576"  links:   - dbdb:  image: postgres  environment:    POSTGRES_PASSWORD: docker    POSTGRES_USER: docker

然后用docker-compose启动它:

core@ku1 /tmp/i $ docker-compose -f dc.yaml upCreating i_db_1...Creating i_web_1...Attaching to i_db_1, i_web_1db_1  | okdb_1  | creating template1 database in /var/lib/postgresql/data/base/1 ... okdb_1  | initializing pg_authid ... okdb_1  | initializing dependencies ... okdb_1  | creating system views ... okdb_1  | loading system objects' descriptions ... okdb_1  | creating collations ... okdb_1  | creating conversions ... okdb_1  | creating dictionaries ... okdb_1  | setting privileges on built-in objects ... okdb_1  | creating information schema ... okdb_1  | loading PL/pgSQL server-side language ... okdb_1  | vacuuming database template1 ... okdb_1  | copying template1 to template0 ... okdb_1  | copying template1 to postgres ... okdb_1  | syncing data to disk ... okdb_1  | db_1  | WARNING: enabling "trust" authentication for local connectionsdb_1  | You can change this by editing pg_hba.conf or using the option -A, ordb_1  | --auth-local and --auth-host, the next time you run initdb.db_1  | db_1  | Success. You can now start the database server using:db_1  | db_1  |     postgres -D /var/lib/postgresql/datadb_1  | ordb_1  |     pg_ctl -D /var/lib/postgresql/data -l logfile startdb_1  | db_1  | db_1  | PostgreSQL stand-alone backend 9.4.1db_1  | backend> statement: CREATE DATAbase "docker" ;db_1  | db_1  | backend> db_1  | db_1  | PostgreSQL stand-alone backend 9.4.1db_1  | backend> statement: CREATE USER "docker" WITH SUPERUSER PASSWORD 'docker' ;db_1  | db_1  | backend> db_1  | LOG:  database system was shut down at 2015-04-12 22:01:12 UTCdb_1  | LOG:  database system is ready to accept connectionsdb_1  | LOG:  autovacuum launcher started^Z[1]+  Stopped      docker-compose -f dc.yaml upcore@ku1 /tmp/i $ bg

您可以看到用户和密码已创建。我执行:

core@ku1 /tmp/i $ docker exec -it i_web_1 psql -Udocker -h db userPassword for user docker: psql: FATAL:  password authentication failed for user "docker"core@ku1 /tmp/i $db_1  | FATAL:  password authentication failed for user "docker"db_1  | DETAIL:  Connection matched pg_hba.conf line 95: "host all all 0.0.0.0/0 md5"core@ku1 /tmp/i $ docker exec -it i_web_1 psql -Udocker -h db userPassword for user docker: psql: FATAL:  database "user" does not existdb_1  | FATAL:  database "user" does not exist

因此,我唯一能想到的是您正在尝试从主机而不是Web容器连接到数据库?还是您的Web容器未将“
db”用作连接的主机?您对Web容器的定义不包含任何我可以看到的错误。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/370319.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号