Skip to content

Cannot access dockerized local Postgres container from Linux machine #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bengineerdavis opened this issue Jan 8, 2020 · 9 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@bengineerdavis
Copy link

Referring to #12 and #3.

On Fedora 30, I'm having issues using command from hackernoon article references in #12.

Ran docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres

Resulted in a hash. No container present when I used the docker ps command.

(source)
If I modify the command to: docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres, I get a working container of Postgres.

Going back to the article above, I then use the command psql -h localhost -U postgres -d postgres , I get this message:

psql -h localhost -U postgres -d postgres psql: /usr/pgsql-11/lib/libpq.so.5: no version information available (required by psql) psql: /usr/pgsql-11/lib/libpq.so.5: no version information available (required by psql) 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?

I suspect this is an issue with my Fedora setup, but anyone with Linux experience would be greatly appreciated for insights.

@angelocordon
Copy link

If your Postgres is running in a Docker container, I believe you have to run any psql commands against Docker (docker exec container-name psql, or something like that)

@bengineerdavis
Copy link
Author

@angelocordon I had a feeling that maybe I should open up a terminal inside the container. However, @lpatmo did confirm that psql -h localhost -U postgres -d postgres works from outside the container, since we're logging into it like a remote db.

@lpatmo
Copy link
Member

lpatmo commented Jan 14, 2020

Huh... maybe this issue isn't linux-specific. I got the same problem on OSX just now:

(env) Lindas-MacBook-Pro-2:cbv3_django_prototype lpnotes$ docker run --rm   --name pg-docker -e POSTGRES_PASSWORD=docker -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data  postgres
1123de60702889e11a9a47d12bdc3c57d6891ec14c2289c8886094f8b3886754
(env) Lindas-MacBook-Pro-2:cbv3_django_prototype lpnotes$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
(env) Lindas-MacBook-Pro-2:cbv3_django_prototype lpnotes$ psql -h localhost -U postgres -d 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?
(env) Lindas-MacBook-Pro-2:cbv3_django_prototype lpnotes$ 

@BethanyG
Copy link
Member

According to this issue, the order of the commands might screw things up (although it doesn't on my OSX machine, and I have no idea why): docker-library/postgres#592

Try switching things around to:

docker run --rm -d -p 5432:5432 --name pg-docker -e POSTGRES_PASSWORD=docker -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres

@lpatmo
Copy link
Member

lpatmo commented Jan 15, 2020

@bengineerdavis Earlier this afternoon I got the same error, and it turned out that:

1/ I had too many postgres images (which I ended up deleting)
2/ I had docker pulled postgres 12 (latest) instead of doing docker pull postgres:11.1

I updated https://github.com/codebuddies/django-concept/wiki/Contribution-instructions to the best of my ability, but something that would be more useful is probably taking a look at https://github.com/codebuddies/django-concept/pull/44/files, which @billglover worked on. Is there any chance you can try taking a look at that/following the setup instructions there, when you have time?

Thanks!

@billglover billglover added the bug Something isn't working label Jan 16, 2020
@billglover
Copy link
Contributor

Do you still have this issue with docker-compose as introduced in #44?

@bengineerdavis
Copy link
Author

bengineerdavis commented Jan 28, 2020 via email

@billglover
Copy link
Contributor

With #44 now merged into master and confirmed as working on Linux, Mac OS, and Windows I'm closing this for now. We can reopen this if issues with Linux remain.

@bengineerdavis
Copy link
Author

bengineerdavis commented Feb 3, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants