Ich habe eine VM, die mit Vagrant über Bash Provisioning eingerichtet ist.Zugriff auf postgresql in einem Docker-Container von einem VM
Ich versuche, eine Reihe von Anwendungen und Tools indeode die VM beim Start und einige davon benötigen eine PostgreSQL-Datenbank. Ich zog die Bereitstellungsphase auf nur die notwendigen Teile umfassen:
install.sh:
function installPostgresql() {
docker pull postgres:9.4
docker run --name dbcontainer -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD -e POSTGRES_DB=dbname -e POSTGTES_HOST=localhost -d postgres
}
...
installPostgresql
Dies nutzt eine Standard weit verbreitet Docker für postgresql erstellt. Ich starte es, nachdem ich es aus dem zentralen Repository gezogen habe.
Aus irgendeinem Grunde kann ich den Lauf Postgres Dienst innerhalb meiner VM nicht zugreifen, aber ich CAN es anschließen, wenn ich ausführen/ist/bash auf dem Lauf Docker und verwende psql innerhalb der Docker innerhalb der VM.
Innen VM:
[email protected]:~$ psql -h localhost -p 5432 -U postgres -W
Password for user postgres:
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
Innen Docker innerhalb der VM:
[email protected]:/# psql -h localhost -p 5432 -U postgres -W
Password for user postgres:
psql (9.5.2)
Type "help" for help.
postgres=#
pg_hba.conf:
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
Warum funktioniert es innerhalb des Docker innerhalb der VM, aber nicht "nur" von der VM?