Ruby on Rails app not reachable

Hi guys! I’m trying to deploy a Ruby on Rails web app for the first time, but it’s not working…

I don’t understand what is happening. The log says that the app is not listening on the correct port and host, but I think it is. In fact, the logs of the Puma server show that the host is 0.0.0.0 and the port is 3000.

Could somebody help me?

2024-11-24T10:14:55Z runner[48e290ea749928] mad [info]Machine started in 866ms
2024-11-24T10:14:55Z proxy[48e290ea749928] mad [info]machine started in 880.191048ms
2024-11-24T10:14:55Z proxy[48e290ea749928] mad [info]machine became reachable in 6.735179ms
2024-11-24T10:14:55Z proxy[48e290ea749928] mad [error][PC01] 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 (hint: look at your startup logs, servers often print the address they are listening on)
2024-11-24T10:14:56Z app[48e290ea749928] mad [info]2024/11/24 10:14:56 INFO SSH listening listen_address=[fdaa:0:bc23:a7b:48:7e3c:932f:2]:22 dns_server=[fdaa::3]:53
2024-11-24T10:14:57Z app[48e290ea749928] mad [info]=> Booting Puma
2024-11-24T10:14:57Z app[48e290ea749928] mad [info]=> Rails 7.2.1 application starting in production
2024-11-24T10:14:57Z app[48e290ea749928] mad [info]=> Run `bin/rails server --help` for more startup options
2024-11-24T10:14:59Z app[48e290ea749928] mad [info]Puma starting in single mode...
2024-11-24T10:14:59Z app[48e290ea749928] mad [info]* Puma version: 6.4.3 (ruby 3.3.5-p100) ("The Eagle of Durango")
2024-11-24T10:14:59Z app[48e290ea749928] mad [info]*  Min threads: 5
2024-11-24T10:14:59Z app[48e290ea749928] mad [info]*  Max threads: 5
2024-11-24T10:14:59Z app[48e290ea749928] mad [info]*  Environment: production
2024-11-24T10:14:59Z app[48e290ea749928] mad [info]*          PID: 336
2024-11-24T10:14:59Z app[48e290ea749928] mad [info]* Listening on http://0.0.0.0:3000
2024-11-24T10:14:59Z app[48e290ea749928] mad [info]Use Ctrl-C to stop
2024-11-24T10:15:11Z proxy[48e290ea749928] mad [error][PR04] could not find a good candidate within 21 attempts at load balancing

fly.toml

# fly.toml app configuration file generated for cartly on 2024-11-23T19:30:23+01:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = '###########'
primary_region = 'mad'
console_command = '/rails/bin/rails console'

[build]

[deploy]
release_command = './bin/rails db:prepare'

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

[[mounts]]
source = "########"
destination = "#########"

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1

[[http_service.checks]]
grace_period = "30s"

[[statics]]
guest_path = '/rails/public'
url_prefix = '/'

Dockerfile

# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.3.5
FROM ruby:$RUBY_VERSION-slim AS base

LABEL fly_launch_runtime="rails"

# Rails app lives here
WORKDIR /rails

# Set production environment
ENV BUNDLE_DEPLOYMENT="1" \
    BUNDLE_PATH="/usr/local/bundle" \
    BUNDLE_WITHOUT="development:test" \
    RAILS_ENV="production"

# Update gems and bundler
RUN gem update --system --no-document && \
    gem install -N bundler

# Throw-away build stage to reduce size of final image
FROM base AS build

# Install packages needed to build gems
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y \
    build-essential \
    git \
    pkg-config \
    libpq-dev \
    libz-dev \
    dh-autoreconf \
    libexpat1-dev \
    libglib2.0-dev \
    libvips-dev \
    libvips \
    libvips-tools \
    curl \
    postgresql-client \
    neovim \
    xz-utils && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Install the latest stable LTS version of Node.js
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \
    apt-get install -y nodejs && \
    npm install -g npm@latest

# Install jemalloc
RUN git clone https://github.com/jemalloc/jemalloc.git && \
    cd jemalloc && \
    git checkout 5.2.1 && \
    autoconf && \
    ./configure && \
    make && \
    make install

# Install application gems
COPY Gemfile Gemfile.lock ./
RUN bundle install && \
    bundle exec bootsnap precompile --gemfile && \
    rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git

RUN mkdir /data
COPY ./config/locale /data/locale

# Copy application code
COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile


# Final stage for app image
FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y curl imagemagick libvips postgresql-client && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /rails /rails

# Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \
    useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
    chown -R 1000:1000 db log storage tmp
USER 1000:1000

# Deployment options
ENV RUBY_YJIT_ENABLE="1"

# Entrypoint sets up the container.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD bin/rails server -b 0.0.0.0 -p 3000

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