Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker changes #231

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Docker changes #231

wants to merge 2 commits into from

Conversation

ar-jan
Copy link

@ar-jan ar-jan commented Oct 18, 2024

I tried building and running the frontend via Docker with docker compose up frontend, but this failed:

frontend-1 | bundles vre/main.js → vre/bundle.js...
frontend-1 | [!] (plugin commonjs--resolver) Error: EACCES: permission denied, stat '/root/.node_modules/vre'
frontend-1 | Error: EACCES: permission denied, stat '/root/.node_modules/vre'

Running the frontend container as the unprivileged node user fixes this.

As an aside, is there a benefit to storing the node_modules as a volume rather than just having it in the built container?

Fix "When using COPY with more than one source file, the destination
must be a directory and end with a / or a \"
https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#non-root-user

Fixes errors with `npm install` in building the container:
[!] (plugin commonjs--resolver) Error: EACCES: permission denied, stat '/root/.node_modules/vre'
Error: EACCES: permission denied, stat '/root/.node_modules/vre'
@ar-jan ar-jan changed the title Docker change Docker changes Oct 18, 2024
Copy link
Member

@jgonggrijp jgonggrijp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried building and running the frontend via Docker with docker compose up frontend, but this failed:

frontend-1 | bundles vre/main.js → vre/bundle.js...
frontend-1 | [!] (plugin commonjs--resolver) Error: EACCES: permission denied, stat '/root/.node_modules/vre'
frontend-1 | Error: EACCES: permission denied, stat '/root/.node_modules/vre'

Running the frontend container as the unprivileged node user fixes this.

I am a bit surprised because I don't recall running into such problems myself. But the fix seems reasonable and unproblematic.

As an aside, is there a benefit to storing the node_modules as a volume rather than just having it in the built container?

Yes, it speeds up the build and reduces the need for rebuilds, because the node_modules don't end up creating their own (continuously evolving) image layer.

@@ -1,7 +1,7 @@
FROM python:3.9-bullseye

WORKDIR /usr/src/app/backend
COPY requirements.txt requirements-test.txt .
COPY requirements.txt requirements-test.txt ./
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this slash actually matter or is it just a spurious change by your autoformatter?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was intentional, to resolve a linting issue (When using COPY with more than one source file, the destination must be a directory and end with a / or a \) provided via vscode-docker.

@ar-jan
Copy link
Author

ar-jan commented Oct 30, 2024

I wondered about the node_modules because this setup creates the directory with root ownership on the host system which can be annoying.

@jgonggrijp
Copy link
Member

Isn't that just how Docker volumes are supposed to work? You declare a virtual disk that Docker manages behind your back. It is the same for the database and the python cache. Maybe I'm misunderstanding your question?

@ar-jan
Copy link
Author

ar-jan commented Oct 30, 2024

I don't mean how Docker manages its internals, but that here the local git repository gets an (empty) directory frontend/node_modules owned by root:root. I guess because the volume is mounted into the guest's /usr/src/app dir.

@jgonggrijp
Copy link
Member

Strange. I get that empty directory in the host system as well, but it is owned by me, not by root. Did you run docker-compose up with sudo?

@ar-jan
Copy link
Author

ar-jan commented Oct 30, 2024

No, but by default Docker runs as root. I guess you are running Docker rootless mode?

@jgonggrijp
Copy link
Member

Not consciously? I just installed Docker Desktop and went with it, without configuring anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants