# can't seed with flyctl ssh console -C '/app/bin/rails db:seed'

**URL:** <https://community.fly.io/t/cant-seed-with-flyctl-ssh-console-c-app-bin-rails-db-seed/10443>\
**Category:** Questions / Help\
**Tags:** rails\
**Created:** [January 30, 2023, 5:05pm UTC](https://community.fly.io/t/cant-seed-with-flyctl-ssh-console-c-app-bin-rails-db-seed/10443 "2023-01-30T17:05:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucas-vittaz](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/lucas-vittaz/32/8711_2.png) [@lucas-vittaz](https://community.fly.io/u/lucas-vittaz)\
**Post date:** [January 30, 2023, 5:05pm UTC](https://community.fly.io/t/cant-seed-with-flyctl-ssh-console-c-app-bin-rails-db-seed/10443/1 "2023-01-30T17:05:23Z")

</div>

Hi all,

I just successfully deployed my application, however I am unable to run the rails:db seed with the command flyctl ssh console -C ‘/app/bin/rails db:seed’.

it return this error :  
flyctl ssh console -C ‘/app/bin/rails db:seed’  
Connecting to … … complete  
fork/exec /app/bin/rails: no such file or directory

Can someone help me resolve this issue? thanks 🙂

my docker file :

```auto
# syntax = docker/dockerfile:1

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

# Rails app lives here
WORKDIR /rails
# install git
RUN apt-get update && apt-get install -y git

# Set production environment
ENV RAILS_ENV="production" \
    BUNDLE_PATH="vendor/bundle" \
    BUNDLE_WITHOUT="development:test"

# Update gems and preinstall the desired version of bundler
ARG BUNDLER_VERSION=2.3.7
RUN gem update --system --no-document && \
    gem install -N bundler -v ${BUNDLER_VERSION}

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

# Install Node.js
ARG NODE_VERSION=16.14.2
RUN curl -fsSL https://fnm.vercel.app/install | bash && \
    /root/.local/share/fnm/fnm install $NODE_VERSION
ENV PATH=/root/.local/share/fnm/aliases/default/bin/:$PATH

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

# Install packages needed to build gems and node modules
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y build-essential libpq-dev node-gyp pkg-config python-is-python3 redis

# Install yarn
ARG YARN_VERSION=1.22.15
RUN npm install -g yarn@$YARN_VERSION

# Install application gems
COPY Gemfile Gemfile.lock ./
RUN bundle _${BUNDLER_VERSION}_ install && \
    bundle exec bootsnap precompile --gemfile

# Install node modules
COPY package.json yarn.lock .
RUN yarn install

# 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 ./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 postgresql-client redis && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built application from previous stage
COPY --from=build /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"]

```

fly.toml :

```auto
# fly.toml file generated for jardica on 2023-01-30T17:46:01+01:00

app = "jardica"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]

[experimental]
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 3000
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

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

```

fly.rake :

```auto
# commands used to deploy a Rails application
namespace :fly do
  # BUILD step:
  # - changes to the filesystem made here DO get deployed
  # - NO access to secrets, volumes, databases
  # - Failures here prevent deployment
  task :build => 'assets:precompile'

  # RELEASE step:
  # - changes to the filesystem made here are DISCARDED
  # - full access to secrets, databases
  # - failures here prevent deployment
  task :release => 'db:migrate'

  # SERVER step:
  # - changes to the filesystem made here are deployed
  # - full access to secrets, databases
  # - failures here result in VM being stated, shutdown, and rolled back
  # to last successful deploy (if any).
  task :server => :swapfile do
    sh 'bin/rails server'
  end

  # optional SWAPFILE task:
  # - adjust fallocate size as needed
  # - performance critical applications should scale memory to the
  # point where swap is rarely used. 'fly scale help' for details.
  # - disable by removing dependency on the :server task, thus:
  # task :server do
  task :swapfile do
    sh 'fallocate -l 512M /swapfile'
    sh 'chmod 0600 /swapfile'
    sh 'mkswap /swapfile'
    sh 'echo 10 > /proc/sys/vm/swappiness'
    sh 'swapon /swapfile'
  end
end

```

---

<div class="post-metadata">

**Author:** ![rubys](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/rubys/32/16907_2.png) [@rubys](https://community.fly.io/u/rubys)\
**Post date:** [January 30, 2023, 5:25pm UTC](https://community.fly.io/t/cant-seed-with-flyctl-ssh-console-c-app-bin-rails-db-seed/10443/2 "2023-01-30T17:25:43Z")

</div>

It looks like you are using the new Rails Dockerfiles, just released yesterday. These are being developed to match and ideally be included in Rails 7. See [Cut over to Rails Dockerfile Generator on Sunday 29 Jan 2023](https://community.fly.io/t/cut-over-to-rails-dockerfile-generator-on-sunday-29-jan-2023/10350)

A few things to be aware of:

- If your app is Rails 6 or later you don’t need to run db:seed as `bin/docker-entrypoint` will run db:prepare. See: [Rails 6 adds db:prepare rake task | Saeloun Blog](https://blog.saeloun.com/2019/04/11/rails-6-rails-db-prepare.html)
- Your app is now at `/rails` instead of `/app`.
- If you want to run `/rails/bin/rails` commands directly from `flyctl ssh console`, you will need to update your dockerfile. This can be done with one command: [Dockerfiles and fly.toml · Fly Docs](https://fly.io/docs/rails/getting-started/dockerfiles/#shelling-in)
- `lib/tasks/fly.rake` are no longer used by the build process. Feel free to delete this file.

---

<div class="post-metadata">

**Author:** ![lucas-vittaz](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/lucas-vittaz/32/8711_2.png) [@lucas-vittaz](https://community.fly.io/u/lucas-vittaz)\
**Post date:** [January 30, 2023, 9:28pm UTC](https://community.fly.io/t/cant-seed-with-flyctl-ssh-console-c-app-bin-rails-db-seed/10443/3 "2023-01-30T21:28:29Z")

</div>

Thank you for your help, I didn’t know a new version was released. So I went back to the old Dockerfile configuration for Rails 6 and everything is working 🙂

---

<div class="post-metadata">

**Author:** ![rubys](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/rubys/32/16907_2.png) [@rubys](https://community.fly.io/u/rubys)\
**Post date:** [January 30, 2023, 9:43pm UTC](https://community.fly.io/t/cant-seed-with-flyctl-ssh-console-c-app-bin-rails-db-seed/10443/4 "2023-01-30T21:43:04Z")

</div>

That works too.

Since you are on Rails 6, you might want to change ‘db:migrate’ to ‘db:prepare’ in `lib/tasks/fly.rake'. If you make this change, you won't ever have to run `db:seed` separately again.

---

<div class="post-metadata">

**Author:** ![mbialowas](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@mbialowas](https://community.fly.io/u/mbialowas)\
**Post date:** [March 10, 2023, 3:54pm UTC](https://community.fly.io/t/cant-seed-with-flyctl-ssh-console-c-app-bin-rails-db-seed/10443/5 "2023-03-10T15:54:39Z")

</div>

I have the same issue, not able to seed database. I can ssh into fly by running fly ssh console but whenever I run rails db:seed it give me /bin/sh: 5: rails: not found. I deployed an app fine.

Rails 7.0.4.2  
Ruby

fly.toml file

```auto
# fly.toml file generated for seinfeld on 2023-03-08T14:46:53-06:00

app = "seinfeld"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]

[experimental]
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 3000
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

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

```

dockerfile

```auto
# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=2.7.7
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

# 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 pkg-config

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

# 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 libsqlite3-0 postgresql-client && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Run and own the application files as a non-root user for security
RUN useradd rails --home /rails --shell /bin/bash
USER rails:rails

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build --chown=rails:rails /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"]

```

Please advise what you did to fix. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![rubys](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/rubys/32/16907_2.png) [@rubys](https://community.fly.io/u/rubys)\
**Post date:** [March 10, 2023, 4:05pm UTC](https://community.fly.io/t/cant-seed-with-flyctl-ssh-console-c-app-bin-rails-db-seed/10443/6 "2023-03-10T16:05:55Z")

</div>

> [@mbialowas](#):
>
> I can ssh into fly by running fly ssh console but whenever I run rails db:seed it give me /bin/sh: 5: rails: not found.

You shouldn’t have to run db:seed, db:prepare should take care of it for you.

But if you do want to run db:seed (or other rails commands), try:

```auto
cd /rails
bin/rails db:seed

```

If you are going to be using `fly ssh console` frequently (I certainly do!), you might want to modify your Dockerfile and entrypoint to enable “sudo”. Instructions for doing that can be found here: [Running Tasks & Consoles · Fly Docs](https://fly.io/docs/rails/the-basics/run-tasks-and-consoles/#interactive-shell)

---

<div class="post-metadata">

**Author:** ![mbialowas](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@mbialowas](https://community.fly.io/u/mbialowas)\
**Post date:** [March 10, 2023, 4:23pm UTC](https://community.fly.io/t/cant-seed-with-flyctl-ssh-console-c-app-bin-rails-db-seed/10443/7 "2023-03-10T16:23:32Z")

</div>

worked like a charm - thank you!
