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.