Improve Dockerfile non-root user setup#26
Merged
justinkumpe merged 2 commits intomasterfrom Jun 28, 2025
Merged
Conversation
Contributor
Reviewer's GuideRefactors the Dockerfile to properly establish a non-root user with a home directory before installing dependencies, configure pip cache and local directories with correct ownership, and ensure the application directory is owned by that user. Flow diagram for improved non-root user setup in Dockerfileflowchart TD
Start([Start Docker build])
CreateGroup[Create non-root group]
CreateUser[Create non-root user with home directory]
InstallDeps[Install Python dependencies]
CopyFiles[Copy application files]
ChownApp[Chown /app to non-root]
MkdirPip[Create /home/non-root/.cache/pip and .local]
ChownHome[Chown /home/non-root to non-root]
SwitchUser[Switch to non-root user]
RunApp[Run application]
Start --> CreateGroup --> CreateUser --> InstallDeps --> CopyFiles --> ChownApp --> MkdirPip --> ChownHome --> SwitchUser --> RunApp
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Member
Author
|
@sourcery-ai review |
Contributor
There was a problem hiding this comment.
Hey @justinkumpe - I've reviewed your changes - here's some feedback:
- Consider combining the user/group creation, directory setup, and chown commands into a single RUN instruction to reduce the number of Docker layers.
- You’re creating a pip cache directory but still using --no-cache-dir; either remove that flag to leverage the cache or drop the cache setup step if it isn’t needed.
- Add ENV HOME=/home/non-root (or similar) so that the non-root user’s home directory is correctly picked up by pip and other tools.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider combining the user/group creation, directory setup, and chown commands into a single RUN instruction to reduce the number of Docker layers.
- You’re creating a pip cache directory but still using --no-cache-dir; either remove that flag to leverage the cache or drop the cache setup step if it isn’t needed.
- Add ENV HOME=/home/non-root (or similar) so that the non-root user’s home directory is correctly picked up by pip and other tools.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Optimize Dockerfile by establishing a non-root user with a proper home directory and setting correct permissions for application and pip cache directories.
Enhancements: