Skip to content

Optimize Docker Build: Integrated File Ownership#6268

Open
4MZ4 wants to merge 1 commit intoFlowiseAI:mainfrom
4MZ4:quickfix-chown
Open

Optimize Docker Build: Integrated File Ownership#6268
4MZ4 wants to merge 1 commit intoFlowiseAI:mainfrom
4MZ4:quickfix-chown

Conversation

@4MZ4
Copy link
Copy Markdown

@4MZ4 4MZ4 commented Apr 22, 2026

Refactored the build process to use the --chown flag directly within the COPY instruction. This replaces the secondary RUN chown -R command, eliminating a massive file-system layer and bypassing the high-latency overhead of recursive ownership changes. This change significantly reduces build times and shrinks the final image footprint by avoiding redundant data duplication.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request optimizes the Dockerfile by utilizing the --chown flag within the COPY instruction and removing a subsequent recursive chown command to reduce image layers. However, a critical permission issue was identified: because the pnpm install and build commands are still executed as the root user, the resulting node_modules and build artifacts will be owned by root. This will likely cause permission errors when the container switches to the node user at runtime. It is recommended to switch to the node user before copying the source and running the build process.

Comment thread Dockerfile
Comment on lines +31 to 32
COPY --chown=node:node . .
# Install dependencies and build
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

While using --chown=node:node in the COPY instruction is a good optimization to avoid a heavy recursive chown layer, removing the RUN chown -R node:node . command without adjusting the build user introduces a permission issue.

Currently, pnpm install and pnpm build are executed as the root user. Consequently, the node_modules directory and build artifacts (like dist folders) will be owned by root. When the container switches to USER node at runtime, the application may encounter permission errors if it attempts to write to these directories (e.g., for local storage, logs, or cache).

To fix this and maintain the optimization, switch to the node user before copying the source and running the build. This ensures that all files generated during the build process are owned by the correct user. Note that you must first ensure the working directory is owned by the node user.

RUN chown node:node .
USER node
COPY --chown=node:node . .

# Install dependencies and build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant