I’m developing an application using Next.js for the frontend and Rails for the backend. Initially, I was able to access the default pages provided by Rails and Next.js locally without any issues. However, after deploying my application to Fly.io using fly deploy
, I encountered a problem where the machine repeatedly reboots and eventually moves into a suspended state.
I suspect the issue might be related to the differences between my development and production Dockerfiles. Here are the excerpts for reference:
- Dockerfile.dev(for development)
FROM ruby:3.2.2
WORKDIR /app
RUN apt-get update -qq && apt-get install -y build-essential default-mysql-client vim openssl ca-certificates
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN gem install bundler
RUN bundle install
COPY . /app
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]
- Dockerfile(for production)
# syntax = docker/dockerfile:1
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.2.2
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 default-libmysqlclient-dev
# Install application gems
COPY --link Gemfile Gemfile.lock ./
RUN bundle install && \
bundle exec bootsnap precompile --gemfile && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
# Copy application code
COPY --link . .
# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/
# 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 default-mysql-client openssl ca-certificates && \
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
# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server"]
Additionally, I noticed bootsnap-related errors in the deployment logs, as shown below:
fetch: Operation not permitted - /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/yaml.rb (Errno::EPERM)
In an attempt to resolve this, I modified the boot.rb
file to include a custom cache directory, but the issue persists:
- boot.rb
Bootsnap.setup(
cache_dir: '/tmp/bootsnap',
development_mode: ENV['RAILS_ENV'] == 'development',
load_path_cache: true,
autoload_paths_cache: true,
compile_cache_iseq: true,
compile_cache_yaml: true
)
Here are the relevant parts of the logs from Fly.io:
- Logs
2024-01-31T16:03:25.725 app[9080553c372587] nrt [info] 2024/01/31 16:03:25 listening on [fdaa:5:b097:a7b:b4f0:e5e5:fec4:2]:22 (DNS: [fdaa::3]:53)
2024-01-31T16:03:26.719 app[9080553c372587] nrt [info] [ 2.231753] reboot: Restarting system
2024-01-31T16:03:26.842 runner[9080553c372587] nrt [info] machine did not have a restart policy, defaulting to restart
2024-01-31T16:03:28.467 app[9080553c372587] nrt [info] [ 0.033169] PCI: Fatal: No config space access function found
2024-01-31T16:03:28.638 app[9080553c372587] nrt [info] INFO Starting init (commit: 366341b)...
2024-01-31T16:03:28.653 app[9080553c372587] nrt [info] INFO starting statics vsock server
2024-01-31T16:03:28.654 app[9080553c372587] nrt [info] INFO Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as 1000
2024-01-31T16:03:28.664 app[9080553c372587] nrt [info] INFO [fly api proxy] listening at /.fly/api
2024-01-31T16:03:28.672 app[9080553c372587] nrt [info] 2024/01/31 16:03:28 listening on [fdaa:5:b097:a7b:b4f0:e5e5:fec4:2]:22 (DNS: [fdaa::3]:53)
2024-01-31T16:03:29.241 app[9080553c372587] nrt [info] /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/iseq.rb:64:in `fetch': Operation not permitted - /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/yaml.rb (Errno::EPERM)
2024-01-31T16:03:29.241 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/iseq.rb:64:in `fetch'
2024-01-31T16:03:29.241 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/iseq.rb:89:in `load_iseq'
2024-01-31T16:03:29.241 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache.rb:24:in `require_relative'
2024-01-31T16:03:29.241 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache.rb:24:in `setup'
2024-01-31T16:03:29.241 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap.rb:67:in `setup'
2024-01-31T16:03:29.241 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap.rb:110:in `default_setup'
2024-01-31T16:03:29.241 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/setup.rb:5:in `<top (required)>'
2024-01-31T16:03:29.241 app[9080553c372587] nrt [info] from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
2024-01-31T16:03:29.241 app[9080553c372587] nrt [info] from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
2024-01-31T16:03:29.241 app[9080553c372587] nrt [info] from /rails/config/boot.rb:4:in `<top (required)>'
2024-01-31T16:03:29.241 app[9080553c372587] nrt [info] from ./bin/rails:3:in `require_relative'
2024-01-31T16:03:29.241 app[9080553c372587] nrt [info] from ./bin/rails:3:in `<main>'
2024-01-31T16:03:29.667 app[9080553c372587] nrt [info] INFO Main child exited normally with code: 1
2024-01-31T16:03:29.668 app[9080553c372587] nrt [info] INFO Starting clean up.
2024-01-31T16:03:29.669 app[9080553c372587] nrt [info] WARN hallpass exited, pid: 306, status: signal: 15 (SIGTERM)
2024-01-31T16:03:29.673 app[9080553c372587] nrt [info] 2024/01/31 16:03:29 listening on [fdaa:5:b097:a7b:b4f0:e5e5:fec4:2]:22 (DNS: [fdaa::3]:53)
2024-01-31T16:03:30.666 app[9080553c372587] nrt [info] [ 2.228303] reboot: Restarting system
2024-01-31T16:03:30.798 runner[9080553c372587] nrt [info] machine did not have a restart policy, defaulting to restart
2024-01-31T16:03:41.821 app[9080553c372587] nrt [info] [ 0.033604] PCI: Fatal: No config space access function found
2024-01-31T16:03:41.999 app[9080553c372587] nrt [info] INFO Starting init (commit: 366341b)...
2024-01-31T16:03:42.014 app[9080553c372587] nrt [info] INFO starting statics vsock server
2024-01-31T16:03:42.016 app[9080553c372587] nrt [info] INFO Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as 1000
2024-01-31T16:03:42.025 app[9080553c372587] nrt [info] INFO [fly api proxy] listening at /.fly/api
2024-01-31T16:03:42.032 app[9080553c372587] nrt [info] 2024/01/31 16:03:42 listening on [fdaa:5:b097:a7b:b4f0:e5e5:fec4:2]:22 (DNS: [fdaa::3]:53)
2024-01-31T16:03:42.561 app[9080553c372587] nrt [info] /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/iseq.rb:64:in `fetch': Operation not permitted - /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/yaml.rb (Errno::EPERM)
2024-01-31T16:03:42.561 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/iseq.rb:64:in `fetch'
2024-01-31T16:03:42.561 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/iseq.rb:89:in `load_iseq'
2024-01-31T16:03:42.561 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache.rb:24:in `require_relative'
2024-01-31T16:03:42.561 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache.rb:24:in `setup'
2024-01-31T16:03:42.561 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap.rb:67:in `setup'
2024-01-31T16:03:42.561 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap.rb:110:in `default_setup'
2024-01-31T16:03:42.561 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/setup.rb:5:in `<top (required)>'
2024-01-31T16:03:42.561 app[9080553c372587] nrt [info] from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
2024-01-31T16:03:42.561 app[9080553c372587] nrt [info] from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
2024-01-31T16:03:42.561 app[9080553c372587] nrt [info] from /rails/config/boot.rb:4:in `<top (required)>'
2024-01-31T16:03:42.561 app[9080553c372587] nrt [info] from ./bin/rails:3:in `require_relative'
2024-01-31T16:03:42.561 app[9080553c372587] nrt [info] from ./bin/rails:3:in `<main>'
2024-01-31T16:03:43.026 app[9080553c372587] nrt [info] INFO Main child exited normally with code: 1
2024-01-31T16:03:43.026 app[9080553c372587] nrt [info] INFO Starting clean up.
2024-01-31T16:03:43.028 app[9080553c372587] nrt [info] WARN hallpass exited, pid: 306, status: signal: 15 (SIGTERM)
2024-01-31T16:03:43.032 app[9080553c372587] nrt [info] 2024/01/31 16:03:43 listening on [fdaa:5:b097:a7b:b4f0:e5e5:fec4:2]:22 (DNS: [fdaa::3]:53)
2024-01-31T16:03:44.027 app[9080553c372587] nrt [info] [ 2.237223] reboot: Restarting system
2024-01-31T16:03:44.159 runner[9080553c372587] nrt [info] machine did not have a restart policy, defaulting to restart
2024-01-31T16:03:47.477 app[9080553c372587] nrt [info] [ 0.032986] PCI: Fatal: No config space access function found
2024-01-31T16:03:47.667 app[9080553c372587] nrt [info] INFO Starting init (commit: 366341b)...
2024-01-31T16:03:47.682 app[9080553c372587] nrt [info] INFO starting statics vsock server
2024-01-31T16:03:47.683 app[9080553c372587] nrt [info] INFO Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as 1000
2024-01-31T16:03:47.692 app[9080553c372587] nrt [info] INFO [fly api proxy] listening at /.fly/api
2024-01-31T16:03:47.701 app[9080553c372587] nrt [info] 2024/01/31 16:03:47 listening on [fdaa:5:b097:a7b:b4f0:e5e5:fec4:2]:22 (DNS: [fdaa::3]:53)
2024-01-31T16:03:48.260 app[9080553c372587] nrt [info] /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/iseq.rb:64:in `fetch': Operation not permitted - /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/yaml.rb (Errno::EPERM)
2024-01-31T16:03:48.260 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/iseq.rb:64:in `fetch'
2024-01-31T16:03:48.260 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/iseq.rb:89:in `load_iseq'
2024-01-31T16:03:48.260 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache.rb:24:in `require_relative'
2024-01-31T16:03:48.260 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache.rb:24:in `setup'
2024-01-31T16:03:48.260 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap.rb:67:in `setup'
2024-01-31T16:03:48.260 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap.rb:110:in `default_setup'
2024-01-31T16:03:48.260 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/setup.rb:5:in `<top (required)>'
2024-01-31T16:03:48.260 app[9080553c372587] nrt [info] from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
2024-01-31T16:03:48.260 app[9080553c372587] nrt [info] from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
2024-01-31T16:03:48.260 app[9080553c372587] nrt [info] from /rails/config/boot.rb:4:in `<top (required)>'
2024-01-31T16:03:48.260 app[9080553c372587] nrt [info] from ./bin/rails:3:in `require_relative'
2024-01-31T16:03:48.260 app[9080553c372587] nrt [info] from ./bin/rails:3:in `<main>'
2024-01-31T16:03:48.693 app[9080553c372587] nrt [info] INFO Main child exited normally with code: 1
2024-01-31T16:03:48.693 app[9080553c372587] nrt [info] INFO Starting clean up.
2024-01-31T16:03:48.694 app[9080553c372587] nrt [info] WARN hallpass exited, pid: 306, status: signal: 15 (SIGTERM)
2024-01-31T16:03:48.699 app[9080553c372587] nrt [info] 2024/01/31 16:03:48 listening on [fdaa:5:b097:a7b:b4f0:e5e5:fec4:2]:22 (DNS: [fdaa::3]:53)
2024-01-31T16:03:49.696 app[9080553c372587] nrt [info] [ 2.249575] reboot: Restarting system
2024-01-31T16:03:49.825 runner[9080553c372587] nrt [info] machine did not have a restart policy, defaulting to restart
2024-01-31T16:04:18.114 app[9080553c372587] nrt [info] [ 0.032453] PCI: Fatal: No config space access function found
2024-01-31T16:04:18.288 app[9080553c372587] nrt [info] INFO Starting init (commit: 366341b)...
2024-01-31T16:04:18.303 app[9080553c372587] nrt [info] INFO starting statics vsock server
2024-01-31T16:04:18.304 app[9080553c372587] nrt [info] INFO Preparing to run: `/rails/bin/docker-entrypoint ./bin/rails server` as 1000
2024-01-31T16:04:18.312 app[9080553c372587] nrt [info] INFO [fly api proxy] listening at /.fly/api
2024-01-31T16:04:18.320 app[9080553c372587] nrt [info] 2024/01/31 16:04:18 listening on [fdaa:5:b097:a7b:b4f0:e5e5:fec4:2]:22 (DNS: [fdaa::3]:53)
2024-01-31T16:04:18.812 app[9080553c372587] nrt [info] /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/iseq.rb:64:in `fetch': Operation not permitted - /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/yaml.rb (Errno::EPERM)
2024-01-31T16:04:18.812 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/iseq.rb:64:in `fetch'
2024-01-31T16:04:18.812 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache/iseq.rb:89:in `load_iseq'
2024-01-31T16:04:18.812 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache.rb:24:in `require_relative'
2024-01-31T16:04:18.812 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/compile_cache.rb:24:in `setup'
2024-01-31T16:04:18.812 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap.rb:67:in `setup'
2024-01-31T16:04:18.812 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap.rb:110:in `default_setup'
2024-01-31T16:04:18.812 app[9080553c372587] nrt [info] from /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.0/lib/bootsnap/setup.rb:5:in `<top (required)>'
2024-01-31T16:04:18.812 app[9080553c372587] nrt [info] from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
2024-01-31T16:04:18.812 app[9080553c372587] nrt [info] from <internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
2024-01-31T16:04:18.812 app[9080553c372587] nrt [info] from /rails/config/boot.rb:4:in `<top (required)>'
2024-01-31T16:04:18.812 app[9080553c372587] nrt [info] from ./bin/rails:3:in `require_relative'
2024-01-31T16:04:18.812 app[9080553c372587] nrt [info] from ./bin/rails:3:in `<main>'
2024-01-31T16:04:19.313 app[9080553c372587] nrt [info] INFO Main child exited normally with code: 1
2024-01-31T16:04:19.314 app[9080553c372587] nrt [info] INFO Starting clean up.
2024-01-31T16:04:19.315 app[9080553c372587] nrt [info] WARN hallpass exited, pid: 306, status: signal: 15 (SIGTERM)
2024-01-31T16:04:19.320 app[9080553c372587] nrt [info] 2024/01/31 16:04:19 listening on [fdaa:5:b097:a7b:b4f0:e5e5:fec4:2]:22 (DNS: [fdaa::3]:53)
2024-01-31T16:04:20.315 app[9080553c372587] nrt [info] [ 2.231479] reboot: Restarting system
2024-01-31T16:04:20.436 runner[9080553c372587] nrt [info] machine has reached its max restart count (10)
Has anyone experienced similar issues, or does anyone have insights on how to resolve this problem? Any help or suggestions would be greatly appreciated.