<p>I'm trying to get Redocly's <a href="https://github.com/Redocly/developer-portal-starter" rel="nofollow noreferrer">developer portal</a> running in kubernetes. I need to use nginix because the developer portal doesn't bind to anything else than localhost so I'm using nginx to proxy to localhost. I keep running into permission issues with the app running and nginx. I fixed the nginx permissions (I think) by adding this to the dockerfile (def not good but can't figure out how else):</p>
<pre><code>RUN chmod -R 777 /var
RUN chmod -R 777 /etc/nginx
</code></pre>
<p>My Dockerfile looks like this:</p>
<pre><code>FROM docker.abc.cc/node:16-alpine

# Define arguments and environment variables
ARG ARTIFACTORY_USERNAME
ARG ARTIFACTORY_PASSWORD
ENV ARTIFACTORY_USERNAME=$ARTIFACTORY_USERNAME
ENV ARTIFACTORY_PASSWORD=$ARTIFACTORY_PASSWORD

# Add curl and bash for debugging
RUN apk add --no-cache curl bash nginx

# Install npm-cli-login
RUN npm install -g npm-cli-login

WORKDIR /usr/src/app

# Log in to Artifactory
RUN \
    npm-cli-login \
    -u $ARTIFACTORY_USERNAME \
    -p $ARTIFACTORY_PASSWORD \
    -e $ARTIFACTORY_USERNAME@abc.com \
    -r https://artifactory.abc.cc/artifactory/api/npm/npm

# Copy package files and install dependencies
COPY --chown=node package*.json /usr/src/app/
RUN npm install --legacy-peer-deps

# Copy application files
COPY --chown=node . /usr/src/app/

# Add Nginx configuration file
COPY nginx.conf /etc/nginx/nginx.conf

RUN chmod -R 777 /usr/src
RUN chmod -R 777 /var
RUN chmod -R 777 /etc/nginx

# Start Nginx and the application
CMD [&quot;sh&quot;, &quot;-c&quot;, &quot;nginx &amp;&amp; npm start&quot;]

# Expose the Nginx port
EXPOSE 3001
</code></pre>
<p>and the relevant part of my deployment looks like this:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: caas-dev-portal
  namespace: internal-tools
spec:
  replicas: 2
  revisionHistoryLimit: 3
    spec:
      containers:
      - env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        envFrom:
        - configMapRef:
            name: caas-dev-portal
        - configMapRef:
            name: abc-k8s-cluster-info
        - secretRef:
            name: apm-settings
        image: docker.abc.cc/caas-portal:v1test
        imagePullPolicy: Always
        lifecycle:
          preStop:
            exec:
              command:
              - /bin/sleep
              - &quot;30&quot;
        name: web
        ports:
        - containerPort: 3001
          name: http-api
        - containerPort: 9999
          name: http-management
        resources:
          limits:
            cpu: 1500m
            ephemeral-storage: 1Gi
            memory: 1024Mi
          requests:
            cpu: 100m
            ephemeral-storage: 10Mi
            memory: 128Mi
        startupProbe:
          failureThreshold: 45
          httpGet:
            path: /health
            port: http-api
          periodSeconds: 4
      imagePullSecrets:
      - name: artifactory-docker-registry
      restartPolicy: Always
      serviceAccountName: caas-dev-portal
      terminationGracePeriodSeconds: 40
</code></pre>
<p>I then see this error in the app logs:</p>
<pre><code>/usr/src/app/node_modules/yoga-layout-prebuilt/yoga-layout/build/Release/nbind.js:53
        throw ex;
        ^

Error: EPERM: operation not permitted, copyfile '/usr/src/app/package.json' -&gt; '/usr/src/app/node_modules/@redocly/developer-portal/dist/engine/package.json'
    at copyFileSync (node:fs:2847:3)
    at runCommand (/usr/src/app/node_modules/@redocly/developer-portal/dist/cli/run-command.js:1:356)
    at Object.handler (/usr/src/app/node_modules/@redocly/developer-portal/dist/cli.js:2:1376)
    at Object.runCommand (/usr/src/app/node_modules/@redocly/developer-portal/node_modules/yargs/build/index.cjs:446:48)
    at Object.parseArgs [as _parseArgs] (/usr/src/app/node_modules/@redocly/developer-portal/node_modules/yargs/build/index.cjs:2697:57)
    at Object.get [as argv] (/usr/src/app/node_modules/@redocly/developer-portal/node_modules/yargs/build/index.cjs:2651:25)
    at Object.&lt;anonymous&gt; (/usr/src/app/node_modules/@redocly/developer-portal/dist/cli.js:2:4118)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Module.load (node:internal/modules/cjs/loader:1076:32) {
  errno: -1,
  syscall: 'copyfile',
  code: 'EPERM',
  path: '/usr/src/app/package.json',
  dest: '/usr/src/app/node_modules/@redocly/developer-portal/dist/engine/package.json'
}
npm notice
npm notice New major version of npm available! 8.19.4 -&gt; 9.8.1
npm notice Changelog: &lt;https://github.com/npm/cli/releases/tag/v9.8.1&gt;
npm notice Run `npm install -g npm@9.8.1` to update!
npm notice
</code></pre>
<p>It looks like the app doesn't have permissions to fully run but I can't quite figure out how to give it the right permissions. I've even added <code>RUN chmod -R 777 /usr/src</code> in the Dockerfile right before I run <code>CMD</code> but still get this error.</p>
<p>whats the best way to fix my permissions issue so I can get both nginx and the app to run?</p>

lightweight
<p>Below troubleshooting steps will help you to resolve your issue:</p>
<p>1.As you are using older version try clean cache with <code>npm cache clean --force</code>, install the latest version of npm globally as admin:  <code>npm install -g npm@latest --force or npm install -g npm@9.8.1</code></p>
<p>2.Try to remove the read-only attribute from the project folder.</p>
<p>3.As per this <a href="https://discuss.circleci.com/t/docker-build-fails-with-nonsensical-eperm-operation-not-permitted-copyfile/37364" rel="nofollow noreferrer">issue</a> you need to specify a Docker version using the version attribute. BY adding below code in docker file :</p>
<pre><code>- setup_remote_docker:
    version: 19.03.13
</code></pre>
<p>4.You are using <code>RUN chmod -R 777</code> which is not recommended as it sets the permissions to read, write, and execute for the owner, group, and others, which means that everyone has full access to the directory and its contents.</p>
<pre><code>Try sudo chown $USER:$USER -R __YOUR_PROJECT__DIRECTORY__ 

Or sudo chmod -R 775 &lt;/img/folder and project/folder&gt;
</code></pre>
<p>Note: If you need to change permissions on files or directories that exist outside of the container you need to use sudo, If you need to change permissions on files or directories within a Docker container, you should use the RUN command.</p>
