instance refused connection. is your app listening on 0.0.0.0:3000? make sure it is not only listening on 127.0.0.1

I deployed my Rails application, but it’s not working due to the following error, resulting in an HTTP ERROR 502. Could you help me resolve this issue?

...
`instance refused connection. is your app listening on 0.0.0.0:3000? make sure it is not only listening on 127.0.0.1`
...

Below is the Dockerfile:

...
# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
# Start server via Thruster by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/thrust", "./bin/rails", "server"]
...

This Dockerfile was automatically generated by the rails new command.
/rails/bin/docker-entrypoint is as follows:

#!/bin/bash -e

# Enable jemalloc for reduced memory usage and latency.
if [ -z "${LD_PRELOAD+x}" ]; then
    LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit)
    export LD_PRELOAD
fi

# If running the rails server then create or migrate existing database
if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then
  ./bin/rails db:prepare
fi

exec "${@}"

Below is the fly.toml file:

app = 'xxx'
primary_region = 'xxx'

[build]
dockerfile = 'Dockerfile'

[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 1
processes = ['app']

[[vm]]
memory = '512mb'
cpu_kind = 'shared'
cpus = 1

I tried adding the following to fly.toml, but the error message did not change:

[env]
PORT = "3000"

I replaced the production CMD with the following command, which I use in the development Dockerfile, but the error message remained the same:

- CMD ["./bin/thrust", "./bin/rails", "server"]
+ CMD ["rails", "server", "-b", "0.0.0.0", "-p", "3000"]

I believe the application will work if I can change it to listen on 0.0.0.0:3000, but I’m not sure where to make this change.

What’s in your logs? You are trying the right things, but if your Rails application isn’t starting for other reasons, that would explain this error.

Thank you for reviewing my question and for sharing the documentation link.
By running fly logs, I was able to identify the error and resolve it, which ultimately fixed the HTTP ERROR 502 issue.


When I ran fly logs, the following error was displayed:

ActiveRecord::AdapterNotSpecified: The `cable` database is not configured for the `production` environment.

Since I wasn’t planning to use Action Cable, I had commented out the following cable section in the database.yml file:

production:
  primary: &primary_production
    <<: *default
    database: production
...
  # cable: 
  #   <<: *primary_production 
  #   database: production_cable 
  #   migrations_paths: db/cable_migrate

By uncommenting this section, I was able to resolve the HTTP ERROR 502 issue.


I had been checking the logs in the “Live Logs” section of the fly.io console, but the ActiveRecord::AdapterNotSpecified: error didn’t show up there, so I wasn’t able to notice it.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.