Can't connect to fly console

Hi!
I consistently encounter the error “Error: ssh shell: wait: remote command exited without exit status or exit signal” whenever I attempt to access the Rails console using commands like fly ssh console --pty -C "bin/rails c" in my WSL2 environment.
I have another Rails app developed in the same conditions and I don’t have any problems getting into the Rails console by the same commands.
I kept re-installing openssh-client & openssh-server and change the configuration but without success.
I’m not an expert in SSH and I feel like I tried all the solutions I found. Do you guys have any suggestions? Is anyone available and willing to debug this together in a session maybe? I’ll appreciate any kind of help :smiley:

Note:
Is there any way to get into the Rails console without using SSH?
Is there any way to get into the Rails console of my app within the Fly.io platform? If not, do you guys think of adding this feature soon?

If your app doesn’t have a volume, try fly console.

Otherwise, try fly ssh console with no parameters.

P.S. fly ssh console doesn’t use your locally installed openssh-console.

Thanks for replying!
I saw this and added

task :console do
  sh 'fly ssh console --pty -C "/rails/bin/rails console"'
end

into lib/tasks/fly.rake and after running bin/rails fly:console --trace, I get:

** Invoke fly:console (first_time)
** Execute fly:console
fly ssh console --pty -C "/rails/bin/rails console"
Connecting to <MACHINE_HASH>... complete
Error: ssh shell: wait: remote command exited without exit status or exit signal
rails aborted!
Command failed with status (1): [fly ssh console --pty -C "/rails/bin/rails...]
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/file_utils.rb:67:in `block in create_shell_runner'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/file_utils.rb:57:in `sh'
/mnt/c/Ubuntu/kaia/lib/tasks/fly.rake:17:in `block (2 levels) in <main>'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
/.rvm/gems/ruby-3.1.2/gems/sentry-ruby-5.12.0/lib/sentry/rake.rb:24:in `execute'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
/.rvm/gems/ruby-3.1.2/gems/railties-7.0.8/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
/.rvm/gems/ruby-3.1.2/gems/railties-7.0.8/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/.rvm/rubies/ruby-3.1.2/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
/.rvm/gems/ruby-3.1.2/gems/railties-7.0.8/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/.rvm/gems/ruby-3.1.2/gems/railties-7.0.8/lib/rails/command.rb:51:in `invoke'
/.rvm/gems/ruby-3.1.2/gems/railties-7.0.8/lib/rails/commands.rb:18:in `<main>'
/.rvm/gems/ruby-3.1.2/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/.rvm/gems/ruby-3.1.2/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => fly:console

You’ve been with us for a while!

If memory serves, the Dockerfiles produced at that time placed the app into /app instead of /rails.

Look for WORKDIR in the Dockerfile, or run fly ssh console and when you get a prompt run pwd.

Assuming the WORKDIR is /app, the correct command would be:

fly ssh console --pty -C "/app/bin/rails console"

Hey, sorry for the confusion but I’m having these problems with an app on my company’s email (minerzz.it@gmail) which was created like 2 months ago - I know I’m logged in here from my personal account. :sweat_smile:

I have WORKDIR /rails in my Dockerfile (I can’t remember how I generated the Dockerfile or where I got this from :sweat_smile:)

Running fly ssh console works but I’m getting ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. when running /bin/rails c inside.

node --version returns -bash: node: command not found but /usr/local/node/bin/node --version return the correct version 20.10.0 => I think it’s a problem with the ENV PATH.

My current Dockerfile contains

...
# Install Node.js
ARG NODE_VERSION=20.10.0
ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
rm -rf /tmp/node-build-master
...
# Build options
ENV PATH="/usr/local/node/bin:$PATH"
...

Screenshot 2023-12-19 164635

I fixed that problem within the connection but when I try to run bin/rails console afterwards the connection ends suddenly.
I also tried to append $PATH instead of adding the Node’s path at the start of $PATH in Dockerfile and re-deploy the app but I’m getting the same error regarding ExecJS::RuntimeUnavailable (and it looks like Node’s path is not added at all to $PATH). Am I doing something wrong?

Here’s the whole Dockerfile for more context:

# syntax = docker/dockerfile:1

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

LABEL fly_launch_runtime="rails"

# Rails app lives here
WORKDIR /rails

# Set production environment
ENV RAILS_ENV="production" \
    BUNDLE_WITHOUT="development:test" \
    BUNDLE_DEPLOYMENT="1"

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

# Install packages needed to install nodejs
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y curl && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Install Node.js
ARG NODE_VERSION=20.10.0
ENV PATH="$PATH:/usr/local/node/bin"
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
    /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
    rm -rf /tmp/node-build-master

# 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 libpq-dev

# Build options
ENV PATH="$PATH:/usr/local/node/bin"

# 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/

# Adjust binfiles to set current working directory
RUN grep -l '#!/usr/bin/env ruby' /rails/bin/* | xargs sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)'

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE=DUMMY ./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 postgresql-client && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails

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

# Deployment options
ENV RAILS_LOG_TO_STDOUT="1" \
    RAILS_SERVE_STATIC_FILES="true"

# 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"]

Most likely, if you look at your logs you will see that you ran out of memory, see:

I just upgraded to 512MB and it worked! Thanks a lot!

P.S.: I still don’t understand why Node is not installed properly from the Dockerfile during the build phase (I keep having to run export PATH=“$PATH:/usr/local/node/bin” before accessing my console). Do you have any suggestions on that?

I can’t explain that. When I ssh into my applications, the env I see is as defined in the Dockerfile.

It shouldn’t be necessary, but try adding the ENV statement in the final build stage (i.e., after the last FROM statement in the Dockerfile).

Another thing to try is adding a “RUN cp /usr/local/node/bin/* /usr/local/bin” statement.

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