Chapter 11: Running tests in Linux seems to have a db configuration issue

After following the instructions to the best of my ability I got stuck when trying to test it.
I must say that instead of Postgres I stuck with MySQL.
My docker-compose file:

    version: '3.3'
          - mysql-test
        build: .
        - DATABASE_HOSTNAME=mysql-test
        - DATABASE_PORT=3308
        image: "mysql/mysql-server:5.7"
          - MYSQL_DATABASE=vapor-test
          - MYSQL_USER=vapor
          - MYSQL_PASSWORD=password

the db configuration excerpt from my configure.swift

    if (env == .testing) {
        databaseName = "vapor-test"
        if let testPort = Environment.get("DATABASE_PORT") {
            databasePort = Int(testPort) ?? 3308
        } else {
            databasePort = 3308
    } else {
        databaseName = "vapor"
        databasePort = 3307

    let hostname = Environment.get("DATABASE_HOSTNAME") ?? "localhost"

    let databaseConfig = MySQLDatabaseConfig(hostname: hostname,
                                            port: databasePort,
                                            username: "vapor",
                                            password: "password",
                                            database: databaseName)
    let database = MySQLDatabase(config: databaseConfig)
    databases.add(database: database, as: .mysql)

The end resulting error is:

[ INFO ] Migrating 'mysql' database (/package/.build/checkouts/fluent.git-7321833952610167324/Sources/Fluent/Migration/MigrationConfig.swift:69)
my-app_1  | Fatal error: 'try!' expression unexpectedly raised an error: NIO.ChannelError.connectFailed(NIO.NIOConnectionError(host: "mysql-test", port: 3308, dnsAError: nil, dnsAAAAError: nil, connectionErrors: [NIO.SingleConnectionFailure(target: [IPv4]mysql-test:3308, error: connection reset (error set): Connection refused (errno: 111))])): file /home/buildnode/jenkins/workspace/oss-swift-4.2-package-linux-ubuntu-16_04/swift/stdlib/public/core/ErrorType.swift, line 184

I’m running in a simple ubuntu machine with swift installed but since its sending everything into docker containers shouldn’t matter much.
Can you help understand what could be the issue?

@0xtim Can you please help with this when you get a chance? Thank you - much appreciated! :]

This is probably caused by the MySQL container not being ready to accept connections when the Vapor app starts up and tries. You can try editing the Dockerfile and adding a sleep in the ENTRYPOINT. Have a look at for more details

Actually, you’re note setting the correct port for your compose environment. By default, MySQL connects on 3306 but you’re trying to connect to 3308. If you change it to 3306 it might work