Reputation: 99
What i am trying to achieve ? I have a rest service running inside a docker which wants to establish a connection to external postgres db host lets say abc.com on port 5432. When i run container it never connects to the remote host and in fact even the localhost fails. Am i missing some step ?
Dockerfile
FROM clojure
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN mv "$(lein with-profile prod uberjar | sed -n 's/^Created \(.*standalone\.jar\)/\1/p')" nameless.jar
EXPOSE 8080
CMD ["java", "-jar", "nameless.jar", "server"]
Upvotes: 6
Views: 439
Reputation: 28
If it is a docker/network issue:
It would be good to show the docker -ps <container-id>
here as well. If the postgres database is external to your computer, like you said abc.com then install some network utility packages and try to ping abc.com and traceroute abc.com to see if you have a connection to it and via which interface.
If you have a ping, then install postgres and connect from the command line. If you can, you should be able to update the URI with the proper string.
If it is outside of your docker image:
If you cannot, then check with the postgres administrator (if you are not the admin) if it accepts outside connections from your IP, how it is configured, etc.
Upvotes: 0
Reputation: 2816
It could be different reasons why it doesn't work.
Networking misconfiguration: docker container runs in an isolated network environment, it knows nothing about postgres server on your localhost. If the connection to abc.com doesn't work either, there could be a problem with dns resolution, you should try to use an ip of the host to troubleshoot it.
Postgres server misconfiguration: take a look to pg_hba.conf and postgresql.conf, there are settings for access restrictions. Check the connectivity from container with the commands pg_isready and psql.
Upvotes: 1