Nanobox app (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused

I’ve post this on SO, but not been able to solve the issue, so trying my luck here too!

I’m playing around with Nanobox for the first time, trying to launch an Elixir app. I have been able to run the app locally ok, but I’m failing with launching a ‘dry-run’ with nanobox deploy dry-runand I get the following error:

! FAILED TO BEFORE_LIVE1: MIX ECTO.CREATE --QUIET !

    Exit
     1

    Command
     su - gonano -c "cd /app; siphon --prefix '' -- bash -i -l -c \"mix ecto.create --quiet\""

    Output

     07:43:15.795 [error] GenServer #PID<0.189.0> terminating
     ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
         (db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2
         (connection) lib/connection.ex:622: Connection.enter_connect/5
         (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
     Last message: nil
     ** (Mix) The database for Codsonline.Repo couldn't be created: an exception was raised:
         ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
             (db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2
             (connection) lib/connection.ex:622: Connection.enter_connect/5
             (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3


Error   : failed to execute hook (before_live) on e528aa7c36b4da40466b9d1d81154f3cbbcb785a278e8435dd20e71eb7f1974c: util:Exec:/opt/nanobox/hooks/before_live: bad exit code(1):
Context : failed to finalize deploy -> failed to run before deploy hooks

I had no issues when originally running mix ecto.create.

config/dev.exs looks like:

config :codsonline, Codsonline.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: System.get_env("DATA_DB_USER"),
  password: System.get_env("DATA_DB_PASS"),
  hostname: System.get_env("DATA_DB_HOST"),
  database: "app_dev",
  pool_size: 10

Psql is running locally.

I’ve also set the port nanobox evar add dry-run PORT=8080

I’ve seen some other questions on this issue, and some comments indicate I might need to change the port Postrges is running or, or at least change the config to port: 5432, although I’m unsure where I would do that.

1 Like

Well whatever the build environment env-vars are for the DATA_DB_* are for the server side is wrong, that is just the very generic ‘The settings you gave me to connect to PostgreSQL are wrong’ message.

Where-ever it is ‘built’ (as in mix ...) check those environment vars there and test them on that remote server, I bet you’ll see they don’t work. :slight_smile:

1 Like

Oh I’m an idiot. I hadn’t removed prod.secret.exs from config/prod.exs

3 Likes

I use Nanobox and wanted to throw in a tip for when you enable SSL. In your app endpoint configuration, you need to set the force_ssl key to the following.

force_ssl: [rewrite_on: [:x_forwarded_proto]]
2 Likes