Der Authentifizierungsfehler, den Sie bekommen haben, würde viel helfen!
feuerte ich das Postgres Bild mit Ihren Argumenten auf:
docker run --name db -d -e POSTGRES_PASSWORD=docker -e POSTGRES_USER=docker postgres
Dann in I exec'ed:
docker exec -it db psql -U docker user
psql: FATAL: database "user" does not exist
ich die Fehlermeldung, die Sie erwarten, weil ich Vertrauen Authentifizierung habe:
docker exec -it db cat /var/lib/postgresql/data/pg_hba.conf | grep -v '^#'
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
host all all 0.0.0.0/0 md5
Um Ihren Webcontainer zu simulieren, werde ich eine andere Instanz des postgres Containers und lin ausführen k den db Behälter und schließen Sie dann zurück an die DB Container:
[email protected] /tmp/i $ docker run --rm --name web --link db:db -it postgres psql -h db -Udocker user
Password for user docker:
psql: FATAL: password authentication failed for user "docker"
ich einen Authentifizierungsfehler, wenn ich das falsche Passwort eingeben. Aber, wenn ich das richtige Passwort eingeben:
[email protected] /tmp/i $ docker run --rm --name web --link db:db -it postgres psql -h db -Udocker user
Password for user docker:
psql: FATAL: database "user" does not exist
Es scheint alles richtig zu funktionieren. Ich habe sie alle in einer YAML-Datei und getestet es auf diese Weise auch:
web:
image: postgres
command: sleep 999
ports:
- "62576:62576"
links:
- db
db:
image: postgres
environment:
POSTGRES_PASSWORD: docker
POSTGRES_USER: docker
dann mit Docker-compose feuert:
[email protected] /tmp/i $ docker-compose -f dc.yaml up
Creating i_db_1...
Creating i_web_1...
Attaching to i_db_1, i_web_1
db_1 | ok
db_1 | creating template1 database in /var/lib/postgresql/data/base/1 ... ok
db_1 | initializing pg_authid ... ok
db_1 | initializing dependencies ... ok
db_1 | creating system views ... ok
db_1 | loading system objects' descriptions ... ok
db_1 | creating collations ... ok
db_1 | creating conversions ... ok
db_1 | creating dictionaries ... ok
db_1 | setting privileges on built-in objects ... ok
db_1 | creating information schema ... ok
db_1 | loading PL/pgSQL server-side language ... ok
db_1 | vacuuming database template1 ... ok
db_1 | copying template1 to template0 ... ok
db_1 | copying template1 to postgres ... ok
db_1 | syncing data to disk ... ok
db_1 |
db_1 | WARNING: enabling "trust" authentication for local connections
db_1 | You can change this by editing pg_hba.conf or using the option -A, or
db_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/data
db_1 | or
db_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1 |
db_1 |
db_1 | PostgreSQL stand-alone backend 9.4.1
db_1 | backend> statement: CREATE DATABASE "docker" ;
db_1 |
db_1 | backend>
db_1 |
db_1 | PostgreSQL stand-alone backend 9.4.1
db_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 UTC
db_1 | LOG: database system is ready to accept connections
db_1 | LOG: autovacuum launcher started
^Z
[1]+ Stopped docker-compose -f dc.yaml up
[email protected] /tmp/i $ bg
Sie können sehen, dass der Benutzer und Passwort erstellt wurden. Ich exec in:
[email protected] /tmp/i $ docker exec -it i_web_1 psql -Udocker -h db user
Password for user docker:
psql: FATAL: password authentication failed for user "docker"
[email protected] /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"
[email protected] /tmp/i $ docker exec -it i_web_1 psql -Udocker -h db user
Password for user docker:
psql: FATAL: database "user" does not exist
db_1 | FATAL: database "user" does not exist
Das einzige, was ich mir vorstellen kann ist, dass Sie in die Datenbank von Ihrem Host zu verbinden versuchen, nicht die Web-Container? Oder verwendet Ihr Web-Container nicht die 'db' als Host, mit dem Sie sich verbinden? Ihre Definition für den Webcontainer enthält keine Fehler, die ich sehen kann.
'@ db' impliziert eine Remote-Verbindung und nichts deutet darauf hin, man sie in' postgresql.conf' erlaubt hat und 'pg_hba.conf', besonders die letzte. Es macht keinen Sinn, die Auth-Fehlermeldung in dieser Frage nicht direkt einzubeziehen. –
Ich habe ein sehr ähnliches Problem. Ich habe die notwendigen Änderungen in 'pg_hba.conf' vorgenommen, um entfernte Verbindungen zu erlauben. Das Problem scheint 'docker-compose' zu sein und ignoriert die Umgebungsvariable' POSTGRES_PASSWORD' – jap1968