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
Network boreas_default Created 0.1s
Container boreas-db-1 Created 0.3s
Container boreas-redwood-1 Created 0.1s
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
-
Access docker container where postgres is running
docker-compose -f ./docker-compose.dev.yml exec db bash
-
Use psql command to interact with PostgreSQL
psql -U redwood -d redwood
-
to exit use /q
-
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.