Skip to content

Update dockerfile to use a rootless user #837

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

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

Conversation

axelpontetto
Copy link
Contributor

Board:


Description:


Notes:


Tasks:

  • Add each element in this format

Risk:


Preview:

@axelpontetto axelpontetto marked this pull request as ready for review September 16, 2024 18:52
@axelpontetto axelpontetto force-pushed the update-dockerfile-to-use-a-rootless-user branch from 7d4b7b0 to 254e743 Compare September 25, 2024 17:59
RUN ln -s /usr/lib/*-linux-gnu/libjemalloc.so.2 /usr/lib/libjemalloc.so.2
USER $USERNAME
Copy link
Contributor

@JulianPasquale JulianPasquale Sep 26, 2024

Choose a reason for hiding this comment

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

Have you tried moving this line up? I assume if we login using this username before running all the copy, we wouldn't need to specify the owner in the command

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I already tried that. Not sure if there is another workaround.

@@ -61,19 +61,32 @@ RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libpq-dev libvips libjemalloc2 && \
apt-get clean

ENV USERNAME rails_api_base
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this way we won't need to change if for all the projects 🙂

Suggested change
ENV USERNAME rails_api_base
ENV USERNAME rails

Comment on lines +64 to +66
ENV USERNAME rails_api_base
ENV USER_UID 1000
ENV USER_GID 1000
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use ENV or ARG here? 🤔 https://docs.docker.com/build/building/variables/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At first I tried using ARG but I remember I had some issues with that. I will take another look.

Base automatically changed from add-volume-for-node_modules to main October 4, 2024 14:28
@santib santib requested a review from Copilot June 20, 2025 20:05
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the Docker configuration to run the application using a rootless user. Key changes include adding a node_modules volume in docker-compose.yml; creating and switching to a non-root user in Dockerfile.dev; and implementing a similar rootless user setup in Dockerfile with appropriate file ownership and permission adjustments.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
docker-compose.yml Adds a dedicated node_modules volume to support the new user setup
Dockerfile.dev Introduces environment variables and commands to create/switch to a rootless user, including ownership and permission adjustments
Dockerfile Similar rootless user setup with additional commands for symlink creation and temporary user switching

COPY --link --chown=$USERNAME:$USERNAME --chmod=700 . .
COPY --from=builder --chown=$USERNAME:$USERNAME --chmod=700 $APP_HOME/public/ $APP_HOME/public/
COPY --from=builder --chown=$USERNAME:$USERNAME --chmod=700 $APP_HOME/tmp/ $APP_HOME/tmp/
COPY --from=builder --chown=$USERNAME:$USERNAME --chmod=700 $APP_HOME/vendor/ $APP_HOME/vendor/

Copy link
Preview

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

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

Consider adding a comment explaining the temporary switch to root for symlink creation to improve future maintainability and clarity.

Suggested change
# Temporarily switch to root to create a symlink for libjemalloc.

Copilot uses AI. Check for mistakes.

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.

2 participants