Uruchomiłem serwer postgresql w oknie dokowanym i odsłoniłem port 5432 przez sudo docker run -it -p 5432:5432 9c421f1a239c bash
i ręcznie uruchomiłem serwer postgres w kontenerze dokowania, ale nie mogę połączyć się z nim za pomocą komendy: psql -h 172.17.0.63 -U venti
. 172.17.0.63
to właściwy adres IP, a venti to moja nazwa użytkownika pg. Ale się błąd:Nie można połączyć się z serwerem postgres w docker
psql: could not connect to server: Connection refused
Is the server running on host "172.17.0.63" and accepting
TCP/IP connections on port 5432?
Moja pg_hba.conf wygląda następująco:
local all postgres peer
host all all 0.0.0.0/0 trust
local all all trust
Łączenie z serwerem pg wewnątrz pojemnika działa skutecznie.
Dockerfile:
FROM ubuntu:12.04
RUN apt-get update
RUN apt-get install -y gcc libc-dev-bin libc6 libc6-dev libssl-dev libkrb5-dev comerr-dev
RUN apt-get install -y postgresql-common libpq-dev postgresql-9.1-postgis --fix-missing
RUN apt-get install -y postgresql postgresql-client
USER postgres
ENV PGDATA /etc/postgresql/9.1/main
ENV LOGDIR /etc/postgresql/9.1/main/postgresql.log
WORKDIR /usr/lib/postgresql/9.1/bin
USER root
RUN apt-get install -y vim
USER postgres
RUN sed -e '90d' -i /etc/postgresql/9.1/main/pg_hba.conf
RUN sed -e '91d' -i /etc/postgresql/9.1/main/pg_hba.conf
RUN echo "host all all 0.0.0.0/0 trust" >> '/etc/postgresql/9.1/main/pg_hba.conf'
RUN echo "local all all trust" >> '/etc/postgresql/9.1/main/pg_hba.conf'
RUN ./pg_ctl start && sleep 8 && ./createdb pg && ./createdb bloodstone \
&& createuser -Upostgres -s venti \
&& createdb -Uventi -Oventi venti
# ENTRYPOINT ./pg_ctl start && bash -c "while true; do echo "" > /dev/null; sleep 1; done"
VOLUME $PGDATA
EXPOSE 5432
brakuje (parametr -p portu przed 5432: 5432) w poleceniu, jeśli to nie jest literówka –
@ChandanNayak Niestety, to tylko literówka ... – kxxoling
Czy na telefonie kontener nadal działa po wyjściu z uruchomionego kontenera? Ponieważ nie uruchamiasz go z parametrem -d –