<p>I am working on rails application and it uses Docker and Kubernetes.</p>
<p>I do not know Docker and Kubernetes and I need to run the seed file on the production server but it's not working.</p>
<p>Following is my Docker file</p>
<pre><code>FROM ruby:2.6.5-alpine

RUN apk update
RUN apk add bash build-base libxml2-dev libxslt-dev postgresql postgresql-dev nodejs vim 
yarn libc6-compat curl

RUN mkdir /app
WORKDIR /app
COPY template-app/Gemfile* ./
RUN gem install bundler &amp;&amp; bundle config https://gem.abc.io/xyz/ nvHuX- 
OXxLY2OpiQkFVfgnYgd4ertyufdds
RUN bundle install
#RUN bundle exec rake db:seed(not working)

COPY template-app/ .

EXPOSE 3000

CMD [&quot;bundle&quot;, &quot;exec&quot;, &quot;rails&quot;, &quot;server&quot;, &quot;-b&quot;, &quot;0.0.0.0&quot;, &quot;-p&quot;, &quot;3000&quot;]
</code></pre>
<p>In the Docker file, I have added RUN bundle exec rake db:seed but it's not working and my build is not passed(deployed)</p>
<p>I am using postgres database.</p>
<p>I do not have docker composer file.</p>
<p>Thanks.</p>
<p>Edit:</p>
<p>I got the following error when I write rake db:migrate in the docker file</p>
<pre><code>Removing intermediate container 3634d992e850
---&gt; 1bd575429f8e
Step 9/12 : RUN bundle exec rake db:seed
---&gt; Running in f5d8c63f7db7
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/usr/local/bundle/gems/rake-13.0.1/exe/rake:27:in `&lt;top (required)&gt;'
/usr/local/bundle/bin/bundle:23:in `load'
/usr/local/bundle/bin/bundle:23:in `&lt;main&gt;'
(See full trace by running task with --trace)
</code></pre>
<p>Edit</p>
<p>I have added following code in dockerfile</p>
<pre><code>RUN yarn install --check-files
RUN bundle exec rake db:seed
</code></pre>
<p>I am able to run the seed command but get the following error</p>
<p><a href="https://i.stack.imgur.com/NikmV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NikmV.png" alt="enter image description here" /></a></p>
<p>Edit</p>
<p>My application directory structure</p>
<p><a href="https://i.stack.imgur.com/eMoIR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eMoIR.png" alt="enter image description here" /></a></p>
<p>Here my rails app is in template-app folder and dockerfile is outside the folder</p>
<p>Database.yml file</p>
<pre><code>default: &amp;default
  adapter: postgresql
  encoding: unicode
  pool: &lt;%= ENV[&quot;RAILS_DB_POOL&quot;] || ENV['RAILS_MAX_THREADS'] || 5 %&gt;
  idle_timeout: &lt;%= ENV[&quot;RAILS_IDLE_CONNECTION&quot;] ||  60 %&gt;
  port: &lt;%= ENV['RAILS_DATABASE_PORT'] || 5432 %&gt;

# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
development:
  &lt;&lt;: *default
  adapter: postgresql
  database: &lt;%= ENV['TEMPLATEAPP_DATABASE'] %&gt;
  username: &lt;%= ENV['TEMPLATEAPP_DATABASE_USER'] %&gt;
  password: &lt;%= ENV['TEMPLATEAPP_DATABASE_PASSWORD'] %&gt;
  host: &lt;%= ENV['TEMPLATE_DATABASE_HOSTNAME'] %&gt;

test:
  &lt;&lt;: *default
  adapter: postgresql
  database: &lt;%= ENV['TEMPLATEAPP_DATABASE'] %&gt;
  username: &lt;%= ENV['TEMPLATEAPP_DATABASE_USER'] %&gt;
  password: &lt;%= ENV['TEMPLATEAPP_DATABASE_PASSWORD'] %&gt;
  host: &lt;%= ENV['TEMPLATE_DATABASE_HOSTNAME'] %&gt;


production:
  &lt;&lt;: *default
  adapter: postgresql
  database: &lt;%= ENV['TEMPLATEAPP_DATABASE'] %&gt;
  username: &lt;%= ENV['TEMPLATEAPP_DATABASE_USER'] %&gt;
  password: &lt;%= ENV['TEMPLATEAPP_DATABASE_PASSWORD'] %&gt;
  host: &lt;%= ENV['TEMPLATE_DATABASE_HOSTNAME'] %&gt;
</code></pre>

<p>Well there are lot of things going on in your Dockerfile, first you are installing postgresql but you are not doing its initial configuration. Normal we use docker-compose file and use pre build postgresql for it with following docker image</p>
<pre><code>  db:
    image: postgres:11
    ports:
      - &quot;5432:5432&quot;
    volumes:
      - '../../tmp/data/pg11:/var/lib/postgresql/data:cached'
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: ''
      POSTGRES_HOST_AUTH_METHOD: trust
      PGDATA: /var/lib/postgresql/data/pgdata
</code></pre>
<p>Now another issue is you are using rails 6 mean you have to run yarn to install all packages. so I also added following line</p>
<pre><code>RUN yarn install --check-files

</code></pre>
<p>The other issue is you are running your db migration before copying your project. you can use following Dockerfile</p>
<pre><code>FROM ruby:2.6.5-alpine

RUN apk update
RUN apk add bash build-base libxml2-dev libxslt-dev postgresql postgresql-contrib postgresql-dev nodejs vim yarn libc6-compat curl

RUN mkdir /app
WORKDIR /app
COPY template-app/Gemfile* ./
RUN gem install bundler
# RUN gem install bundler &amp;&amp; bundle config https://gem.abc.io/xyz/ nvHuX- 
RUN bundle install

COPY template-app/ .
RUN yarn install --check-files
RUN bundle exec rake db:seed

EXPOSE 3000

CMD [&quot;bundle&quot;, &quot;exec&quot;, &quot;rails&quot;, &quot;server&quot;, &quot;-b&quot;, &quot;0.0.0.0&quot;, &quot;-p&quot;, &quot;3000&quot;]
</code></pre>
<p>But as I told you due to postgresql it wont' work, till you setup postgres and take consideration using its credentials in your config/database.yml file.</p>
<p>Please use following format</p>
<pre><code>default: &amp;default
  adapter: postgresql
  encoding: unicode
  pool: &lt;%= ENV[&quot;RAILS_DB_POOL&quot;] || ENV['RAILS_MAX_THREADS'] || 5 %&gt;
  idle_timeout: &lt;%= ENV[&quot;RAILS_IDLE_CONNECTION&quot;] ||  60 %&gt;
  port: &lt;%= ENV['RAILS_DATABASE_PORT'] || 5432 %&gt;

# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
development:
  &lt;&lt;: *default
  adapter: postgresql
  database: &lt;%= ENV['TEMPLATEAPP_DATABASE'] %&gt;
  username: &lt;%= ENV['TEMPLATEAPP_DATABASE_USER'] %&gt;
  password: &lt;%= ENV['TEMPLATEAPP_DATABASE_PASSWORD'] %&gt;
  host: &lt;%= ENV['TEMPLATE_DATABASE_HOSTNAME'] %&gt;

test:
  &lt;&lt;: *default
  adapter: postgresql
  database: &lt;%= ENV['TEMPLATEAPP_DATABASE'] %&gt;
  username: &lt;%= ENV['TEMPLATEAPP_DATABASE_USER'] %&gt;
  password: &lt;%= ENV['TEMPLATEAPP_DATABASE_PASSWORD'] %&gt;
  host: &lt;%= ENV['TEMPLATE_DATABASE_HOSTNAME'] %&gt;
</code></pre>
