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

Allows specifying another user to have zsh installed for within environment using -u argument #28

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

balancedscorpion
Copy link

@balancedscorpion balancedscorpion commented Jul 29, 2024

This change allows running zsh in a docker container for a non-root user

This addresses the issue described in #27

Primary changes:

1. User Specification:

Added a new option -u to specify the target user.

u)  TARGET_USER=$OPTARG
    ;;

This defaults to the user running the script (usually root) by introducing TARGET_USER variable, defaulting to the current user:

TARGET_USER=$(whoami)

2. Home Directory Determination

Replaced hardcoded home directory with dynamic determination, which changes depending on the target user.

TARGET_HOME=$(getent passwd "$TARGET_USER" | cut -d: -f6)

Testing

I have tested this works for both no argument (default) and a user argument.

Here's the changes required in docker to the script that I used for testing:

Default (no user argument):

No changes are required to the script. But I used my fork to test it:

RUN sh -c "$(curl -L https://raw.githubusercontent.com/balancedscorpion/zsh-in-docker/new_user/zsh-in-docker.sh)" -- \

Specified user

When changing the user, I've first created a user, then added the -u argument (sample credentials below)

RUN useradd -m dockeruser && echo "dockeruser:dockerpassword" | chpasswd && adduser dockeruser sudo

RUN sh -c "$(curl -L https://raw.githubusercontent.com/balancedscorpion/zsh-in-docker/new_user/zsh-in-docker.sh)" --
-u dockeruser \

Then to close out the Dockerfile:

USER dockeruser

CMD ["/bin/zsh"]

@balancedscorpion balancedscorpion marked this pull request as draft July 30, 2024 16:49
Jamie Martin and others added 2 commits August 1, 2024 16:51
@balancedscorpion balancedscorpion marked this pull request as ready for review August 1, 2024 16:31
@balancedscorpion
Copy link
Author

PR is now ready for review and if ok with it to be merged.

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