OAuth implementation using docker compose gives Error " pq: relation \"hydra_jwk\" does not exist "

I am implementing OAuth on my linux based server using 5 Minute Tutorial. and facing below error

here is the logs after executing this docker command $ docker-compose -p hydra up --build

Step 1/16 : FROM golang:1.10-alpine
 ---> bd36346540f3
Step 2/16 : ARG git_tag
 ---> Using cache
 ---> 047eaddfaae6
Step 3/16 : ARG git_commit
 ---> Using cache
 ---> bdc011ad5d38
Step 4/16 : RUN apk add --no-cache git build-base curl
 ---> Using cache
 ---> eb76d7720d7a
Step 5/16 : RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
 ---> Using cache
 ---> 01be9ca609ac
Step 6/16 : WORKDIR /go/src/github.com/ory/hydra
 ---> Using cache
 ---> dc2fe1bda044
Step 7/16 : ADD ./Gopkg.lock ./Gopkg.lock
 ---> Using cache
 ---> ccfd881bae5b
Step 8/16 : ADD ./Gopkg.toml ./Gopkg.toml
 ---> Using cache
 ---> 8db413b9ad1d
Step 9/16 : RUN dep ensure -vendor-only
 ---> Using cache
 ---> cb73a15aad06
Step 10/16 : ADD . .
 ---> 5bcdc7693f14
Step 11/16 : RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -X github.com/ory/hydra/cmd.Version=$git_tag -X github.com/ory/hydra/cmd.BuildTime=`TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ'` -X github.com/ory/hydra/cmd.GitHash=$git_commit" -a -installsuffix cgo -o hydra
 ---> Running in f6abfd25409e
Removing intermediate container f6abfd25409e
 ---> 5400f6e002c2
Step 12/16 : FROM scratch
 ---> 
Step 13/16 : COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
 ---> Using cache
 ---> 8c154da5d542
Step 14/16 : COPY --from=0 /go/src/github.com/ory/hydra/hydra /usr/bin/hydra
 ---> 73e634d54e3c
Step 15/16 : ENTRYPOINT ["hydra"]
 ---> Running in 96c5f0a94987
Removing intermediate container 96c5f0a94987
 ---> 51925b2204fa
Step 16/16 : CMD ["serve all"]
 ---> Running in 2c4d7a33011e
Removing intermediate container 2c4d7a33011e
 ---> df09e4637942
Successfully built df09e4637942
Successfully tagged hydra_hydra-migrate:latest
Building hydra
Step 1/16 : FROM golang:1.10-alpine
 ---> bd36346540f3
Step 2/16 : ARG git_tag
 ---> Using cache
 ---> 047eaddfaae6
Step 3/16 : ARG git_commit
 ---> Using cache
 ---> bdc011ad5d38
Step 4/16 : RUN apk add --no-cache git build-base curl
 ---> Using cache
 ---> eb76d7720d7a
Step 5/16 : RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
 ---> Using cache
 ---> 01be9ca609ac
Step 6/16 : WORKDIR /go/src/github.com/ory/hydra
 ---> Using cache
 ---> dc2fe1bda044
Step 7/16 : ADD ./Gopkg.lock ./Gopkg.lock
 ---> Using cache
 ---> ccfd881bae5b
Step 8/16 : ADD ./Gopkg.toml ./Gopkg.toml
 ---> Using cache
 ---> 8db413b9ad1d
Step 9/16 : RUN dep ensure -vendor-only
 ---> Using cache
 ---> cb73a15aad06
Step 10/16 : ADD . .
 ---> Using cache
 ---> 5bcdc7693f14
Step 11/16 : RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -X github.com/ory/hydra/cmd.Version=$git_tag -X github.com/ory/hydra/cmd.BuildTime=`TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ'` -X github.com/ory/hydra/cmd.GitHash=$git_commit" -a -installsuffix cgo -o hydra
 ---> Using cache
 ---> 5400f6e002c2
Step 12/16 : FROM scratch
 ---> 
Step 13/16 : COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
 ---> Using cache
 ---> 8c154da5d542
Step 14/16 : COPY --from=0 /go/src/github.com/ory/hydra/hydra /usr/bin/hydra
 ---> Using cache
 ---> 73e634d54e3c
Step 15/16 : ENTRYPOINT ["hydra"]
 ---> Using cache
 ---> 51925b2204fa
Step 16/16 : CMD ["serve all"]
 ---> Using cache
 ---> df09e4637942
Successfully built df09e4637942
Successfully tagged hydra_hydra:latest
Creating hydra_postgresd_1
Creating hydra_hydra-migrate_1
Creating hydra_hydra_1
Creating hydra_consent_1
Attaching to hydra_postgresd_1, hydra_hydra-migrate_1, hydra_hydra_1, hydra_consent_1
postgresd_1      | The files belonging to this database system will be owned by user "postgres".
postgresd_1      | This user must also own the server process.
postgresd_1      | 
postgresd_1      | The database cluster will be initialized with locale "en_US.utf8".
postgresd_1      | The default database encoding has accordingly been set to "UTF8".
postgresd_1      | The default text search configuration will be set to "english".
postgresd_1      | 
postgresd_1      | Data page checksums are disabled.
postgresd_1      | 
postgresd_1      | fixing permissions on existing directory /var/lib/postgresql/data ... ok
postgresd_1      | creating subdirectories ... ok
postgresd_1      | selecting default max_connections ... 100
hydra-migrate_1  | time="2018-11-13T08:07:49Z" level=error msg="An error occurred" error="Could not connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra-migrate_1  | time="2018-11-13T08:07:49Z" level=info msg="Retrying in 0.100000 seconds..."
hydra-migrate_1  | time="2018-11-13T08:07:49Z" level=error msg="An error occurred" error="Could not connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra-migrate_1  | time="2018-11-13T08:07:49Z" level=info msg="Retrying in 0.200000 seconds..."
hydra-migrate_1  | time="2018-11-13T08:07:49Z" level=error msg="An error occurred" error="Could not connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra-migrate_1  | time="2018-11-13T08:07:49Z" level=info msg="Retrying in 0.400000 seconds..."
hydra-migrate_1  | time="2018-11-13T08:07:50Z" level=error msg="An error occurred" error="Could not connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra-migrate_1  | time="2018-11-13T08:07:50Z" level=info msg="Retrying in 0.800000 seconds..."
hydra-migrate_1  | time="2018-11-13T08:07:51Z" level=error msg="An error occurred" error="Could not connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra-migrate_1  | time="2018-11-13T08:07:51Z" level=info msg="Retrying in 1.600000 seconds..."
hydra-migrate_1  | time="2018-11-13T08:07:52Z" level=error msg="An error occurred" error="Could not connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra-migrate_1  | time="2018-11-13T08:07:52Z" level=info msg="Retrying in 3.200000 seconds..."
hydra_1          | Thank you for using ORY Hydra!
hydra_1          | 
hydra_1          | Take security seriously and subscribe to the ORY newsletter. Stay on top of new patches and security insights.                                                                                                
hydra_1          | 
hydra_1          | >> Subscribe now: http://eepurl.com/di390P <<    
hydra_1          | time="2018-11-13T08:07:49Z" level=info msg="Connecting with postgres://*:*@postgresd:5432/hydra?sslmode=disable"
hydra_1          | time="2018-11-13T08:07:49Z" level=info msg="Unable to connect to database" error="Could not Connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra_1          | time="2018-11-13T08:07:49Z" level=info msg="Retrying in 0.100000 seconds..."
hydra_1          | time="2018-11-13T08:07:49Z" level=info msg="Connecting with postgres://*:*@postgresd:5432/hydra?sslmode=disable"
hydra_1          | time="2018-11-13T08:07:49Z" level=info msg="Unable to connect to database" error="Could not Connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra_1          | time="2018-11-13T08:07:49Z" level=info msg="Retrying in 0.200000 seconds..."
hydra_1          | time="2018-11-13T08:07:49Z" level=info msg="Connecting with postgres://*:*@postgresd:5432/hydra?sslmode=disable"
hydra_1          | time="2018-11-13T08:07:49Z" level=info msg="Unable to connect to database" error="Could not Connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra_1          | time="2018-11-13T08:07:49Z" level=info msg="Retrying in 0.400000 seconds..."
hydra_1          | time="2018-11-13T08:07:50Z" level=info msg="Connecting with postgres://*:*@postgresd:5432/hydra?sslmode=disable"
hydra_1          | time="2018-11-13T08:07:50Z" level=info msg="Unable to connect to database" error="Could not Connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra_1          | time="2018-11-13T08:07:50Z" level=info msg="Retrying in 0.800000 seconds..."
hydra_1          | time="2018-11-13T08:07:51Z" level=info msg="Connecting with postgres://*:*@postgresd:5432/hydra?sslmode=disable"
hydra_1          | time="2018-11-13T08:07:51Z" level=info msg="Unable to connect to database" error="Could not Connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra_1          | time="2018-11-13T08:07:51Z" level=info msg="Retrying in 1.600000 seconds..."
hydra_1          | time="2018-11-13T08:07:52Z" level=info msg="Connecting with postgres://*:*@postgresd:5432/hydra?sslmode=disable"
hydra_1          | time="2018-11-13T08:07:52Z" level=info msg="Unable to connect to database" error="Could not Connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra_1          | time="2018-11-13T08:07:52Z" level=info msg="Retrying in 3.200000 seconds..."
postgresd_1      | selecting default shared_buffers ... 128MB
postgresd_1      | selecting dynamic shared memory implementation ... posix
hydra_1          | time="2018-11-13T08:07:55Z" level=info msg="Connecting with postgres://*:*@postgresd:5432/hydra?sslmode=disable"
hydra-migrate_1  | time="2018-11-13T08:07:55Z" level=error msg="An error occurred" error="Could not connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra_1          | time="2018-11-13T08:07:55Z" level=info msg="Unable to connect to database" error="Could not Connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra-migrate_1  | time="2018-11-13T08:07:55Z" level=info msg="Retrying in 6.400000 seconds..."
hydra_1          | time="2018-11-13T08:07:55Z" level=info msg="Retrying in 6.400000 seconds..."
postgresd_1      | creating configuration files ... ok
hydra_1          | time="2018-11-13T08:08:02Z" level=info msg="Connecting with postgres://*:*@postgresd:5432/hydra?sslmode=disable"
hydra_1          | time="2018-11-13T08:08:02Z" level=info msg="Unable to connect to database" error="Could not Connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra-migrate_1  | time="2018-11-13T08:08:02Z" level=error msg="An error occurred" error="Could not connect to SQL: dial tcp 172.19.0.2:5432: connect: connection refused"
hydra_1          | time="2018-11-13T08:08:02Z" level=info msg="Retrying in 12.800000 seconds..."
hydra-migrate_1  | time="2018-11-13T08:08:02Z" level=info msg="Retrying in 12.800000 seconds..."
consent_1        | 
consent_1        | > [email protected] start /usr/src/app
consent_1        | > node ./bin/www
consent_1        | 
postgresd_1      | running bootstrap script ... ok
postgresd_1      | performing post-bootstrap initialization ... ok
postgresd_1      | syncing data to disk ... ok
postgresd_1      | 
postgresd_1      | WARNING: enabling "trust" authentication for local connections
postgresd_1      | You can change this by editing pg_hba.conf or using the option -A, or
postgresd_1      | --auth-local and --auth-host, the next time you run initdb.
postgresd_1      | 
postgresd_1      | Success. You can now start the database server using:
postgresd_1      | 
postgresd_1      |     pg_ctl -D /var/lib/postgresql/data -l logfile start
postgresd_1      | 
postgresd_1      | waiting for server to start....LOG:  database system was shut down at 2018-11-13 08:08:06 UTC
postgresd_1      | LOG:  MultiXact member wraparound protections are now enabled
postgresd_1      | LOG:  database system is ready to accept connections
postgresd_1      | LOG:  autovacuum launcher started
postgresd_1      |  done
postgresd_1      | server started
postgresd_1      | CREATE DATABASE
postgresd_1      | 
postgresd_1      | 
postgresd_1      | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d
postgresd_1      | 
postgresd_1      | LOG:  received fast shutdown request
postgresd_1      | LOG:  aborting any active transactions
postgresd_1      | LOG:  autovacuum launcher shutting down
postgresd_1      | waiting for server to shut down....LOG:  shutting down
postgresd_1      | LOG:  database system is shut down
postgresd_1      |  done
postgresd_1      | server stopped
postgresd_1      | 
postgresd_1      | PostgreSQL init process complete; ready for start up.
postgresd_1      | 
postgresd_1      | LOG:  database system was shut down at 2018-11-13 08:08:12 UTC
postgresd_1      | LOG:  MultiXact member wraparound protections are now enabled
postgresd_1      | LOG:  database system is ready to accept connections
postgresd_1      | LOG:  autovacuum launcher started
hydra_1          | time="2018-11-13T08:08:15Z" level=info msg="Connecting with postgres://*:*@postgresd:5432/hydra?sslmode=disable"
hydra-migrate_1  | Applying `client` SQL migrations...
hydra_1          | time="2018-11-13T08:08:15Z" level=info msg="Connected to SQL!"
postgresd_1      | ERROR:  relation "hydra_jwk" does not exist at character 15
postgresd_1      | STATEMENT:  SELECT * FROM hydra_jwk WHERE sid=$1 ORDER BY created_at DESC
hydra_1          | time="2018-11-13T08:08:15Z" level=fatal msg="Could not fetch private signing key for OpenID Connect - did you forget to run \"hydra migrate sql\" or forget to set the SYSTEM_SECRET?" error="pq: relation \"hydra_jwk\" does not exist"
hydra-migrate_1  | Applied 6 `client` SQL migrations.
hydra-migrate_1  | Applying `oauth2` SQL migrations...
hydra-migrate_1  | Applied 4 `oauth2` SQL migrations.
hydra-migrate_1  | Applying `jwk` SQL migrations...
hydra-migrate_1  | Applied 3 `jwk` SQL migrations.
hydra-migrate_1  | Applying `consent` SQL migrations...
hydra-migrate_1  | Applied 2 `consent` SQL migrations.
hydra-migrate_1  | Migration successful! Applied a total of 15 SQL migrations.
hydra-migrate_1  | Migration successful!
hydra_hydra-migrate_1 exited with code 0

There is no error, what’s the problem? If you think exited with code 0 is an error message, it’s not.

1 Like

Thank you for quick response @hackerman, will you help me little more I am a beginner

I am executing $ docker-compose -p hydra up --build command but every execution time it gives a different error. from last two times, it gives below error.

image