Vapor docker container cannot connect to posgresql

I have a Vapor 4 (swift-tools-version:5.3; Vapor 4.37.1; fluent-postgres-driver 2.1.2) project in development. In my Macbook Pro (latest Catalina) this project working very well in Docker Desktop (Docker version 20.10.2).

I created a new Amazon Linux 2 (x86_64) intance on Amazon EC2 and I installed the docker with amazon-linux-extras install docker command. On Amazon this is the Docker version: Docker version 19.03.13-ce

The migrate command is running to Connection refused error. But I installed the postgresq-client inside vapor-app container and I can connect with to postgresql database. What I'm missing?

root@2fbd8ccb6f50:/app# psql -U psqluser -h psql -p 5432 vapordatabase
Password for user psqluser:
psql (10.15 (Ubuntu 10.15-0ubuntu0.18.04.1), server 11.10)
WARNING: psql major version 10, server major version 11.
         Some psql features might not work.
Type "help" for help.

vapordatabase=# \q
root@2fbd8ccb6f50:/app# ./Run migrate
Migrate Command: Prepare
[ ERROR ] connection reset (error set): Connection refused (errno: 111)
Fatal error: Error raised at top level: connection reset (error set): Connection refused (errno: 111): file /home/buildnode/jenkins/workspace/oss-swift-5.2-package-linux-ubuntu-18_04/swift/stdlib/public/core/ErrorType.swift, line 200
Current stack trace:
0    libswiftCore.so                    0x00007f0ce3deaf90 swift_reportError + 50
1    libswiftCore.so                    0x00007f0ce3e5ca60 _swift_stdlib_reportFatalErrorInFile + 115
2    libswiftCore.so                    0x00007f0ce3b71f3e <unavailable> + 1384254
3    libswiftCore.so                    0x00007f0ce3b71b47 <unavailable> + 1383239
4    libswiftCore.so                    0x00007f0ce3b72128 <unavailable> + 1384744
5    libswiftCore.so                    0x00007f0ce3b70410 _assertionFailure(_:_:file:line:flags:) + 520
6    libswiftCore.so                    0x00007f0ce3bb8d8c <unavailable> + 1674636
7    Run                                0x0000556a50bf20e1 <unavailable> + 9019617
8    libc.so.6                          0x00007f0ce1844b10 __libc_start_main + 231
9    Run                                0x0000556a504a8baa <unavailable> + 1379242
0x7f0ce381397f
0x7f0ce3b70625
0x7f0ce3bb8d8b
0x556a50bf20e0, main at /build/<compiler-generated>:0
0x7f0ce1844bf6
0x556a504a8ba9
0xffffffffffffffff
Illegal instruction (core dumped)
root@2fbd8ccb6f50:/app#

What hostname are you configuring for the Vapor app? A connection timeout indicates it can't reach the server, so it's either the hostname or the port given you can reach it with the client

Thx for reply. The error message was not clear to me where is the connection error: maybe the docker, firewall, etc ...
But now I see what was the issue. I logged out the environment, database to stdout. These settings came from environment file. The .env.production file was inside the contanier already, the CMD in the Dockerfile was "serve --env production --hostname 0.0.0.0". So when I called the "./Run migrate" command the program started with development environment, and because there is no .env.development or even .env file, the database name was nil. So I have to run the migrate command with environment (I think this is not clearly documented): ".Run migrate --env production" or just rename the .env.production to .env in Dockerfile.

Terms of Service

Privacy Policy

Cookie Policy