[GH-ISSUE #109] Connecting to local Postgres DB's on server #88

Closed
opened 2026-02-26 21:34:23 +03:00 by kerem · 5 comments
Owner

Originally created by @ejscheepers on GitHub (Mar 19, 2025).
Original GitHub issue: https://github.com/eduardolat/pgbackweb/issues/109

I am hosting pgbackweb on my own server. On the same server I have the postgres db I want to backup, I don't want to expose the port to the internet.

But if I put localhost or 127.0.0.1 into the connection string the connection fails.

How can I fix this?

Originally created by @ejscheepers on GitHub (Mar 19, 2025). Original GitHub issue: https://github.com/eduardolat/pgbackweb/issues/109 I am hosting pgbackweb on my own server. On the same server I have the postgres db I want to backup, I don't want to expose the port to the internet. But if I put localhost or 127.0.0.1 into the connection string the connection fails. How can I fix this?
kerem closed this issue 2026-02-26 21:34:23 +03:00
Author
Owner

@eduardolat commented on GitHub (Mar 19, 2025):

Try with host.docker.internal instead of localhost and read more about this here.

You can also check the docker network documentation.

<!-- gh-comment-id:2738501935 --> @eduardolat commented on GitHub (Mar 19, 2025): Try with `host.docker.internal` instead of `localhost` and read more about this [here.](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) You can also check the docker [network documentation.](https://docs.docker.com/engine/network/)
Author
Owner

@ejscheepers commented on GitHub (Mar 20, 2025):

Okay I managed to set it up and host.docker.internal works, but if I then
close the port on ufw it still fails.
[image: Eugene Scheepers] http://eugenescheepers.com
Eugene Scheepers
Entrepreneur
eugenescheepers.com

On March 20, 2025 at 1:24 AM, Luis Eduardo @.***)
wrote:

Try with host.docker.internal instead of localhost and read more about
this here.
https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach
You can also check the docker network documentation.
https://docs.docker.com/engine/network/

Reply to this email directly, view it on GitHub
https://github.com/eduardolat/pgbackweb/issues/109#issuecomment-2738501935,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AMOVUN3HW5ETWO3DAKJV64T2VH4B3AVCNFSM6AAAAABZLMPNKOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZYGUYDCOJTGU.
You are receiving this because you authored the thread.Message ID:
@.>
[image: eduardolat]eduardolat left a comment (eduardolat/pgbackweb#109)
https://github.com/eduardolat/pgbackweb/issues/109#issuecomment-2738501935
Try with host.docker.internal instead of localhost and read more about
this here.
https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach
You can also check the docker network documentation.
https://docs.docker.com/engine/network/

Reply to this email directly, view it on GitHub
https://github.com/eduardolat/pgbackweb/issues/109#issuecomment-2738501935,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AMOVUN3HW5ETWO3DAKJV64T2VH4B3AVCNFSM6AAAAABZLMPNKOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZYGUYDCOJTGU.
You are receiving this because you authored the thread.Message ID:
@.
>

<!-- gh-comment-id:2739557219 --> @ejscheepers commented on GitHub (Mar 20, 2025): Okay I managed to set it up and host.docker.internal works, but if I then close the port on ufw it still fails. [image: Eugene Scheepers] <http://eugenescheepers.com> Eugene Scheepers Entrepreneur eugenescheepers.com On March 20, 2025 at 1:24 AM, Luis Eduardo ***@***.***) wrote: > Try with host.docker.internal instead of localhost and read more about > this here. > <https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach> > You can also check the docker network documentation. > <https://docs.docker.com/engine/network/> > — > Reply to this email directly, view it on GitHub > <https://github.com/eduardolat/pgbackweb/issues/109#issuecomment-2738501935>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AMOVUN3HW5ETWO3DAKJV64T2VH4B3AVCNFSM6AAAAABZLMPNKOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZYGUYDCOJTGU>. > You are receiving this because you authored the thread.Message ID: > ***@***.***> > [image: eduardolat]eduardolat left a comment (eduardolat/pgbackweb#109) > <https://github.com/eduardolat/pgbackweb/issues/109#issuecomment-2738501935> > Try with host.docker.internal instead of localhost and read more about > this here. > <https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach> > You can also check the docker network documentation. > <https://docs.docker.com/engine/network/> > — > Reply to this email directly, view it on GitHub > <https://github.com/eduardolat/pgbackweb/issues/109#issuecomment-2738501935>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AMOVUN3HW5ETWO3DAKJV64T2VH4B3AVCNFSM6AAAAABZLMPNKOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZYGUYDCOJTGU>. > You are receiving this because you authored the thread.Message ID: > ***@***.***>
Author
Owner

@eduardolat commented on GitHub (Mar 20, 2025):

That is how docker works, it creates it's own "firewall" via iptables, the best solution in your case is that if your postgresql is running using docker, you can attach both postgresql and pgbackweb to the same docker network and then use the name of the container as the host and docker will handle the underlying communication for you.

You can see an example of that in the PG Back Web README.md example, both of that containers are under the same (implicitly created) network created by docker compose so the containers can communicate each other using the container name

<!-- gh-comment-id:2741148114 --> @eduardolat commented on GitHub (Mar 20, 2025): That is how docker works, it creates it's own "firewall" via iptables, the best solution in your case is that if your postgresql is running using docker, you can attach both postgresql and pgbackweb to the same docker network and then use the name of the container as the host and docker will handle the underlying communication for you. You can see an example of that in the PG Back Web README.md example, both of that containers are under the same (implicitly created) network created by docker compose so the containers can communicate each other using the container name
Author
Owner

@ejscheepers commented on GitHub (Mar 25, 2025):

For anyone else who has this issue, I used Tailscale to solve this issue. This video helped tons: https://www.youtube.com/watch?v=tqvvZhGrciQ&t=1s

<!-- gh-comment-id:2750429393 --> @ejscheepers commented on GitHub (Mar 25, 2025): For anyone else who has this issue, I used Tailscale to solve this issue. This video helped tons: https://www.youtube.com/watch?v=tqvvZhGrciQ&t=1s
Author
Owner

@eduardolat commented on GitHub (Mar 28, 2025):

I'm glad you fixed your problem!

<!-- gh-comment-id:2759943943 --> @eduardolat commented on GitHub (Mar 28, 2025): I'm glad you fixed your problem!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/pgbackweb#88
No description provided.