Skip to content

Commit

Permalink
Changed ownership of .next and node_modules folder to container's…
Browse files Browse the repository at this point in the history
… default non-root user `node`

Error Log:
client    | [Error: EACCES: permission denied, open '/usr/src/app/client/.next/package.json'] {
client    |   errno: -13,
client    |   code: 'EACCES',
client    |   syscall: 'open',
client    |   path: '/usr/src/app/client/.next/package.json'
client    | }

References:
node.js - How to keep node_modules inside container while using docker-compose and a non-root user? - Stack Overflow
https://stackoverflow.com/questions/49941708/how-to-keep-node-modules-inside-container-while-using-docker-compose-and-a-non-r
https://stackoverflow.com/a/49952703
https://stackoverflow.com/questions/49941708/how-to-keep-node-modules-inside-container-while-using-docker-compose-and-a-non-r/49952703#49952703

Docker Compose mounts named volumes as 'root' exclusively · Issue #3270 · docker/compose · GitHub
docker/compose#3270

Stuck with a Problem of access permission denied · Issue #8908 · vercel/next.js · GitHub
vercel/next.js#8908
vercel/next.js#8908 (comment)

What is the best way to use NextJS with docker? · Discussion #16995 · vercel/next.js · GitHub
vercel/next.js#16995

reactjs - error An unexpected error occurred: "EACCES: permission denied - Stack Overflow
https://stackoverflow.com/questions/52713928/error-an-unexpected-error-occurred-eacces-permission-denied

docker - Dockerfile with nextjs and puppteer permission denied - Stack Overflow
https://stackoverflow.com/questions/64565062/dockerfile-with-nextjs-and-puppteer-permission-denied
[RUN chown -Rh $user:$user /home/node]
https://stackoverflow.com/a/64922590
https://stackoverflow.com/questions/64565062/dockerfile-with-nextjs-and-puppteer-permission-denied/64922590#64922590
[More relevant for production build, suggests we modify next.config.js by adding a distDir directive:
module.exports = {
      distDir: 'build',
      serverRuntimeConfig: {
        // Will only be available on the server side
        apiUrl: 'http://signup-api:1984'
      },
      publicRuntimeConfig: {
        // Will be available on both server and client
        apiUrl: 'http://localhost:1984'
      }
    }
]
  • Loading branch information
ChubaOraka committed Aug 22, 2022
1 parent 3f20eaa commit d96f6a0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion client/Dockerfile
Expand Up @@ -4,7 +4,9 @@ WORKDIR /usr/src/app/client

COPY package*.json ./

RUN npm install
RUN mkdir .next && npm install

RUN chown -Rh node:node .next node_modules

EXPOSE 3000

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Expand Up @@ -3,6 +3,7 @@ version: '3.5'
services:
client:
container_name: client
user: node
build:
context: ./client
ports:
Expand Down

0 comments on commit d96f6a0

Please sign in to comment.