<p>I am getting the following error when I am trying to run <code>rake db:migrate</code> on my ec2 instance. I have a RDS postgres instance.</p>

<p><code>Errno::EACCES: Permission denied @ rb_sysopen - /app/db/schema.rb</code>**</p>

<p>below are the relevant contents of my Dockerfile</p>

<pre><code>FROM ubuntu:18.04

RUN apt-get update

RUN useradd -m deploy

WORKDIR /app

RUN mkdir -p vendor
COPY vendor/cache vendor/cache
RUN bundle install --deployment --local --without test development
COPY . .

RUN SECRET_KEY_BASE=111 RAILS_ENV=production bin/rake assets:precompile

RUN mkdir -p tmp/pids
RUN chown -R deploy tmp log

USER deploy
ENV RAILS_LOG_TO_STDOUT 1

EXPOSE 3000
CMD bin/rake db:migrate &amp;&amp; bundle exec passenger start --address 0.0.0.0 --port 3000 --auto --disable-anonymous-telemetry -e production

</code></pre>

<p>here is my deployment yaml file</p>

<pre><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: eks-learning-backend
spec:
  template:
    metadata:
      labels:
        name: eks-learning-backend
    spec:
      containers:
      - name: rails-app
        image: zzz.us-east-1.amazonaws.com/eks:16
        env:
        - name: EKS_DATABASE_NAME
          valueFrom:
            secretKeyRef:
              name: database-config
              key: database_name
        - name: EKS_DATABASE_HOST
          value: zzz.us-east-1.rds.amazonaws.com
        - name: EKS_DATABASE_USERNAME
          valueFrom:
            secretKeyRef:
              name: database-config
              key: username
        - name: EKS_DATABASE_PASSWORD
          valueFrom:
            secretKeyRef:
              name: database-config
              key: password
        - name: RAILS_MASTER_KEY
          value: zzxx
        - name: RAILS_ENV
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
</code></pre>

<p>Any help in this would be really great! Thanks.</p>

opensource-developer
<p>The problem is that the user has insufficient permissions. You only included <code>RUN chown -R deploy tmp log</code> while you also need to give it access to <code>/app/db/</code> dir. 
Adding additional <code>chown</code> for the DB dir will solve the issue. </p>
