SQL migration connection issue in tutorial

Hey everyone,

So I’ve successfully set up and configured my hydra server multiple times now (and even have a working consent app). However, I don’t have a stable server yet (still running on localhost) so I have to set up my server again every time I shut down my computer.

Almost every time I’ve had to do so, I’ve had issues with the following step:

docker run --link ory-hydra-example–postgres:postgres -it --entrypoint hydra oryd/hydra:v0.10.0-alpha.8 migrate sql $DATABASE_URL

It gives me an error like this

ERRO[0075] An error occurred error="Could not connect to SQL: dial tcp xxx.xxx.xxx:5432: getsockopt: connection refused"
INFO[0075] Retrying in 0.100000 seconds…

And I’m unable to figure out why or how to fix it. Sometimes if I switch from one docker tag to another, I’m able to migrate, but other times it won’t work no matter what I do. Has anyone encountered this issue before? What do I do?

This can have two causes:

  1. You’re connecting to postgres too fast - the image is running but it doesn’t accept connections yet. In that case, just wait a few seconds, the migrate command is going to retry until it times out or is successful
  2. You’re using the wrong database URL. Since you redacted your values for DATABASE_URL and also the IP it’s really hard to tell what’s wrong, if you think this is the issue please consider giving the full command chain, including env vars.

I followed the tutorial to the letter up to that point (just copy pasted) so I doubt the DB URL is the problem. I didn’t realize #1 is an possibility but no matter how many times I retry it doesn’t seem to work.

ERRO[0075] An error occurred error=“Could not connect to SQL: dial tcp 23.192.228.106:5432: getsockopt: connection refused”

This is the URL it’s trying to connect to.

Any idea if the docker tag is actually related to the issue? What’s the latest stable tag I should use?

postgres://hydra:secret@postgres:5432/hydra?sslmode=disable and this is the DB URL.

A third possibility is your docker container running postgres, which should be named ory-hydra-example–postgres is no longer running for some reason.

Definitely not the case, I’ve been monitoring the status of the container using docker ps.

Hm, not sure what’s going on on your system. I just ran

$ docker run \
  --name ory-hydra-example--postgres \
  -e POSTGRES_USER=hydra \
  -e POSTGRES_PASSWORD=secret \
  -e POSTGRES_DB=hydra \
  -d postgres:9.6

$ export SYSTEM_SECRET=this_needs_to_be_the_same_always_and_also_very_$3cuR3-._

$ export DATABASE_URL=postgres://hydra:secret@postgres:5432/hydra?sslmode=disable

$ docker run --link ory-hydra-example--postgres:postgres -it --entrypoint hydra oryd/hydra:v0.10.0-alpha.8 migrate sql $DATABASE_URL

without any issues. If you’re running docker on mac / docker on win and don’t have any important stuff running in docker, can you try to factory reset it? Sometimes docker networks are wonky, especially on non-linux.

That worked actually. Weird. Thanks!