0

My docker container has no network options set, but i cant connect to it. This is my docker file:

FROM ubuntu:20.04
ENV DEBIAN_FRONTEND noninteractive
# Install some tools
RUN apt-get update && apt-get install -y g++ clang-7 llvm-7 python make python2.7-dev bison flex libreadline-dev zlib1g-dev perl
COPY . /psql
RUN cd /psql && ./configure --with-llvm && make -j6 && make install && cd src/ext/ && make install-postgres-bitcode
RUN useradd -ms /bin/bash postgres && mkdir /data && chown postgres /data
# postgres as admin user
USER postgres
RUN /usr/local/pgsql/bin/initdb /data
# allow remote connections
VOLUME  ["/data", "/usr/local/pgsql"]
# Set the default command to run when starting the container
EXPOSE 5432
CMD /usr/local/pgsql/bin/pg_ctl -D /data start

Please correct me if i am wrong, but right now, the docker container should have port 5432 open, and PostgreSQL maps by default to 5432, therefore, a connection on 5432 should get forwarded internally to PostgreSQL, right?

So to run it, i use this command:

docker run -p myContainer

But how to connect to the container now? I thought the docker container would be run on localhost, and i could therefore connect to it like this:

./psql -h localhost -p 5432 -U postgres

But i just get errors, that no host is listening or something ... what am i doing wrong?

Clebo Sevic
  • 581
  • 1
  • 7
  • 17
  • You need a `docker run -p 5432:5432` option. `EXPOSE` in the Dockerfile does almost nothing. ("On localhost" is pretty ambiguous here, since the container and the host will have their own independent notions of what "localhost" is.) – David Maze May 28 '21 at 12:46
  • I know, thats what is confsing me. What would be the ip of the docker-container? Some say 172.17.0.XXX or something like that, for others its on the host-localhost, how do o find out? – Clebo Sevic May 28 '21 at 13:53
  • The container-private IP address is an implementation detail that's not useful to know, and it's not reachable except on one very specific Docker-host-OS setup. Don't bother trying to find it. – David Maze May 28 '21 at 14:21

0 Answers0