Permission Error when Spawning rw-vite-dev Process in Docker Container

Hi, I am currently creating a redwood application that was recently upgraded from 4 to 7 and am trying to get the docker experimental functionality working. During this upgrade I followed the upgrade instructions for 5 and 6, without any issues.

Now after building my docker dev container, migrating the database, and then running yarn rw dev in the dev container I am met with an error with vite

node:events:496
throw er; // Unhandled ‘error’ event
^

Error: spawn ps ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:286:19)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted ‘error’ event on ChildProcess instance at:
at ChildProcess._handle.onexit (node:internal/child_process:292:12)
at onErrorNT (node:internal/child_process:484:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -2,
code: ‘ENOENT’,
syscall: ‘spawn ps’,
path: ‘ps’,

I added the ps command to my docker terminal which then spat out the error

node:events:496
web | throw er; // Unhandled ‘error’ event
web | ^
web |
web | Error: spawn rw-vite-dev EACCES
web | at ChildProcess._handle.onexit (node:internal/child_process:286:19)
web | at onErrorNT (node:internal/child_process:484:16)
web | at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
web | Emitted ‘error’ event on ChildProcess instance at:
web | at ChildProcess._handle.onexit (node:internal/child_process:292:12)
web | at onErrorNT (node:internal/child_process:484:16)
web | at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
web | errno: -13,
web | code: ‘EACCES’,
web | syscall: ‘spawn rw-vite-dev’,
web | path: ‘rw-vite-dev’,
web | spawnargs:
web | }

Anyone have any ideas on how to fix the access permission errors?

Hey @Lovelessta90, one gotcha with Vite is that, in dev, it’ll try to open the browser in the container and since there’s no browser to open (or at least the open command it relies on isn’t present), it throws. Have you tried setting [browser].open to false in the toml?

# redwood.toml

[browser]
  open = false

I’ll try that out thanks

The [browser] open = false seems to be the default setting

Gotcha, are you using the Dockerfile provided by Redwood then via yarn rw exp setup-dockerfile?

Yes I followed the Redwood documentation for that, My DockerFile and the docker-compose.dev.yml were just the default files that were generated by running yarn rw exp setup-dockerfile. I already deleted them and re-set up the dockerfiles to see if it cleared the error. The only changes I had to make were deleting the yarnPath from the .yarnrc.yml to get the container to build.

I found a similar issue here [Github Actions]: "EACCES: permission denied, open " for `vite.config` in hosted image run - Stack Overflow I believe

For those with similar issues,

I found another 2 sources that had similar issues

https://www.reddit.com/r/docker/comments/ww6rt5/eacces_permission_denied/

I am not sure if they are having the exact issue, but are generating similar errors.

One is suggesting “The problem is caused by Vite. It’s trying to create a /app/node_modules/.vite directory just before launching the web server.”, while the other is " I’m still not clear on why it wouldn’t work with root user (which should be highest permission possible), but I suspect that might be something to do with node as opposed to Vite…".

I did some permission investigation in the console
drwxr-xr-x 1 node node 4096 Feb 28 02:41 node_modules
-rw-r–r-- 1 node node 423 Feb 28 02:21 vite.config.js

and

grep -r “rw-vite-dev” ./node_modules
./node_modules/@redwoodjs/cli/dist/commands/devHandler.js: ? yarn cross-env NODE_ENV=development rw-vite-dev ${forward} : yarn cross-env NODE_ENV=development RWJS_WATCH_NODE_MODULES=${watchNodeModules ? '1' : ''} webpack serve --config "${webpackDevConfig}" ${forward};
./node_modules/@redwoodjs/vite/package.json: “rw-vite-dev”: “./bins/rw-vite-dev.mjs”,
./node_modules/.yarn-state.yml: “rw-vite-dev”: “@redwoodjs/vite/bins/rw-vite-dev.mjs”

I am investigating whether a

COPY --chown=node:node web/node_modules/.vite .

would be necessary for local dev Docker containers

Versioning
yarn 4.0.2 → deleting yarnPath so reads as 1.22.19
Redwood 7.0.2
Node 20.11.1
Prisma 5.9.0
Ubuntu 22.04.2 LTS

I finally got the container to function properly. I don’t know how to explain it properly but I believe it has to do with the user in the docker container. What would happen is that during the build process I would get

[+] Running 4/4
:heavy_check_mark: Network boreas_default Created 0.1s
:heavy_check_mark: Container boreas-db-1 Created 0.3s
:heavy_check_mark: Container boreas-redwood-1 Created 0.1s
:heavy_check_mark: Container boreas-console-1 Created 0.1s
Attaching to console-1, db-1, redwood-1
db-1 |
db-1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db-1 |
db-1 | 2024-02-29 20:49:33.959 UTC [1] LOG: starting PostgreSQL 16.2 (Debian 16.2-1.pgdg120+2) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
db-1 | 2024-02-29 20:49:33.959 UTC [1] LOG: listening on IPv4 address “0.0.0.0”, port 5432
db-1 | 2024-02-29 20:49:33.960 UTC [1] LOG: listening on IPv6 address “::”, port 5432
db-1 | 2024-02-29 20:49:33.970 UTC [1] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
db-1 | 2024-02-29 20:49:33.984 UTC [29] LOG: database system was shut down at 2024-02-29 20:31:16 UTC
db-1 | 2024-02-29 20:49:33.992 UTC [1] LOG: database system is ready to accept connections
console-1 exited with code 0
redwood-1 | web | ➜ Local: http://localhost:8910/
redwood-1 | web | ➜ Network: http://172.29.0.4:8910/
redwood-1 | web | [Error: EACCES: permission denied, unlink ‘/home/node/app/web/node_modules/.vite/deps_temp_945a6220/package.json’] {
redwood-1 | web | errno: -13,
redwood-1 | web | code: ‘EACCES’,
redwood-1 | web | syscall: ‘unlink’,
redwood-1 | web | path: ‘/home/node/app/web/node_modules/.vite/deps_temp_945a6220/package.json’
redwood-1 | web | }
redwood-1 | api | Building…
redwood-1 | api | [Error: EACCES: permission denied, rmdir ‘/home/node/app/api/dist/directives’] {
redwood-1 | api | errno: -13,
redwood-1 | api | code: ‘EACCES’,
redwood-1 | api | syscall: ‘rmdir’,
redwood-1 | api | path: ‘/home/node/app/api/dist/directives’
redwood-1 | api | }
redwood-1 | gen | Generating full TypeScript definitions and GraphQL schemas
redwood-1 | gen | Done.
redwood-1 | gen |

By adding these 3 lines to the Dockerfile,

RUN mkdir -p /app/node_modules/.vite
&& chown -R node:node /app/node_modules/.vite

RUN mkdir -p /home/node/app/api/dist && chown -R node:node /home/node/app/api/dist

USER root

Inside the Dockerfile that was generated by the setup command
The base should now be


changed # to // for format

// base
// ----
FROM node:20-bookworm-slim as base

RUN corepack enable

// We tried to make the Dockerfile as lean as possible. In some cases, that means we excluded a dependency your project needs.
// By far the most common is Python. If you’re running into build errors because python3 isn’t available,
// uncomment the line below here and in other stages as necessary:
RUN apt-get update && apt-get install -y
openssl
# python3 make gcc
&& rm -rf /var/lib/apt/lists/*

// Create .vite directory and adjust ownership
RUN mkdir -p /app/node_modules/.vite
&& chown -R node:node /app/node_modules/.vite

USER node
WORKDIR /home/node/app

COPY --chown=node:node .yarnrc.yml .
COPY --chown=node:node package.json .
COPY --chown=node:node api/package.json api/
COPY --chown=node:node web/package.json web/
COPY --chown=node:node yarn.lock .

RUN mkdir -p /home/node/.yarn/berry/index
RUN mkdir -p /home/node/.cache

RUN --mount=type=cache,target=/home/node/.yarn/berry/cache,uid=1000
–mount=type=cache,target=/home/node/.cache,uid=1000
CI=1 yarn install

COPY --chown=node:node redwood.toml .
COPY --chown=node:node graphql.config.js .
COPY --chown=node:node .env.defaults .env.defaults

// Add the chown command here to change ownership of /home/node/app/api/dist
RUN mkdir -p /home/node/app/api/dist && chown -R node:node /home/node/app/api/dist

// Switch back to root user for running the development command
USER root


it cleared the error, now I only see the error

node:events:496
web | throw er; // Unhandled ‘error’ event
web | ^
web |
web | Error: spawn rw-vite-dev EACCES
web | at ChildProcess._handle.onexit (node:internal/child_process:286:19)
web | at onErrorNT (node:internal/child_process:484:16)
web | at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
web | Emitted ‘error’ event on ChildProcess instance at:
web | at ChildProcess._handle.onexit (node:internal/child_process:292:12)
web | at onErrorNT (node:internal/child_process:484:16)
web | at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
web | errno: -13,
web | code: ‘EACCES’,
web | syscall: ‘spawn rw-vite-dev’,
web | path: ‘rw-vite-dev’,
web | spawnargs:
web | }

while running yarn rw dev inside the root

Now after creating a user and using

PosgreSQL-Docker database interactions

  1. Access docker container where postgres is running

    docker-compose -f ./docker-compose.dev.yml exec db bash

  2. Use psql command to interact with PostgreSQL

    psql -U redwood -d redwood

  3. to exit use /q

  4. To set User to role admin

UPDATE “User”
SET roles = ‘admin’
WHERE id = 1;

sets the user to admin, refresh the page
and now

I have access to my application when my docker container is running.