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

add an entrypoint.sh script ot inject user/group id dynamically in Docker instance #3168

Closed
benciboy opened this issue Feb 7, 2025 · 0 comments

Comments

@benciboy
Copy link

benciboy commented Feb 7, 2025

Issue

I had problem running docker based Aider with different various error, as a last remedy rewrite userid to my differnet non 1000 one.
RUN useradd -m -u XXXXX -s /bin/bash appuser

As a longterm solution would be to add an entry script which would update appuser ids at runtime , smtnhg like this:

#!/bin/bash
set -e

USER_NAME="appuser"
DEFAULT_UID=1000
DEFAULT_GID=1000

# Update appuser's UID and GID if APP_UID and APP_GID are provided
if [ -n "$APP_UID" ] && [ -n "$APP_GID" ]; then
    echo "Updating $USER_NAME UID/GID to: $APP_UID:$APP_GID"

    # Update group ID
    groupmod -g "$APP_GID" "$USER_NAME"

    # Update user ID
    usermod -u "$APP_UID" -g "$APP_GID" "$USER_NAME"

    # Update ownership of relevant directories
    chown -R $APP_UID:$APP_GID /home/$USER_NAME /app /venv
fi

# Execute the container's command
exec "$@"

Update Dockerfile:

# Copy the entrypoint script and make it executable
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# In the final image stage, set the entrypoint script while keeping appuser as default
USER appuser
ENTRYPOINT ["/entrypoint.sh", "/venv/bin/aider"]

run the image:

docker run -e APP_UID=$(id -u) -e APP_GID=$(id -g) myimage

Version and model info

No response

@benciboy benciboy closed this as completed Feb 7, 2025
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

No branches or pull requests

1 participant