Skip to content
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

Connect to remote database question #10

Open
frenzzy opened this issue Jul 21, 2023 · 0 comments
Open

Connect to remote database question #10

frenzzy opened this issue Jul 21, 2023 · 0 comments

Comments

@frenzzy
Copy link

frenzzy commented Jul 21, 2023

As I see you are not using ports directive in docker-swarm.yml:

db:
image: postgres:15.1-alpine
volumes:
- pgdata:/var/lib/postgresql/data
environment:
- PGUSER=postgres
- POSTGRES_PASSWORD_FILE=/run/secrets/postgres-passwd
secrets:
- postgres-passwd
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5
networks:
- backend

@sidpalas can you please share a knolage on how to connect the database to manage data from your comuter?

I tried to use the following instructions but without success:

What I have tried locally:

cd 12-deploying-containers/docker-swarm
docker context create example --docker "host=ssh://root@example-app-server-ip:22"
docker context use example
docker stack deploy -c docker-swarm.yml example-app # deployed your example to VPS
docker ps # to get container id: 148cac4c4793
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 148cac4c4793 # to get container ip: 10.0.11.3
ssh -L 5432:10.0.11.3:5432 root@example-app-server-ip # connected to docker swarm server
psql --version # psql (PostgreSQL) 15.3 (Homebrew)
psql -h 127.0.0.1 -p 5432 -U postgres postgres

psql: error: connection to server at "127.0.0.1", port 5432 failed: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.

P.S.: Thank you for the tutorial, it is really helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant