3

I have successfully built a postgres-based Docker image that enables PostGIS:

The I run it:

docker run -d -t -p 5432:5432 -v ./data:/data --name postgis-osm-pgrouting -e POSTGRES_PASSWORD=postgres pamtrak06/postgis-pgrouting-osm bash

However, when I try to connect to the database via psql:

psql -h localhost -p 5432 postgres

I get an error:

psql: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

I am a beginner with the port forwarding, but it looks like a port-related issue to me.

Any ideas?

2
  • The container should be able to start without a port forward, so I doubt that's the problem. Can you get access to the server log files? Commented Jun 18, 2018 at 12:58
  • What happens if you remove the -t flag and the bash command from docker run? Commented Jun 18, 2018 at 12:58

2 Answers 2

2

To access an application from within your container you need to first "attach" to that container.

You can do so by running the command:

docker exec -it container_name sh

What this command does is it runs the command sh inside the container container_name

It will prompt a shell terminal where you can now run your psql command like this:

psql -U postgres

Where here you're running psql with the user postgres (default authorized user for psql)

Sign up to request clarification or add additional context in comments.

Comments

-1

try this

docker run -d -t -p 5432:5432 -v $PWD/data:/data --name postgis-osm-pgrouting -e POSTGRES_PASSWORD=postgres pamtrak06/postgis-pgrouting-osm

and then

psql -h localhost -p 5432 postgres

You've got:

psql: could not connect to server: Connection refused
Is the server running on host "192.168.99.101" and accepting
TCP/IP connections on port 5432?

So apply [Configure PostgreSQL to accept TCP/IP connections][https://www.mozmorris.com/2011/11/15/configure-postgresql-to-accept-tcpip-connections.html], but not in production, for tests purpose only !

And override your Dockerfile with this configuration

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.