Closed rorytorneymf closed 3 years ago
This seems to work:
I tried creating a new entrypoint script, that would call the original entrypoint script, then switch the user:
#!/bin/bash
set -e
# Call original entrypoint
/tini -s /startup/startup.sh
# Add new (non-root) user
useradd --shell /bin/bash --system --user-group --create-home appuser
# Run supplied command as non-root user
exec /usr/local/bin/gosu appuser "$@"
Then in my derived Dockerfile just calling this new script:
ADD ./gosu-entrypoint.sh /usr/local/bin/gosu-entrypoint.sh
RUN chmod +x /usr/local/bin/gosu-entrypoint.sh
ENTRYPOINT ["/usr/local/bin/gosu-entrypoint.sh"]
I have a base container that has an
ENTRYPOINT
that needs to run as root:And a derived container that looks like this. Originally I tried using the
USER
directive to change the user:However, running the derived container fails, because
appuser
does not have permissions to execute the startup scripts:So, the
ENTRYPOINT
in the base container needs to run as root, but afterENTRYPOINT
has run on the base container, I'd like to step down in the derived container as a non-root user. I'm trying to figure out how to do that using gosu?I updated the base container to install gosu (using https://hub.docker.com/r/miktex/miktex-test-opensuse/dockerfile as an example as I'm using opensuse):
I'm just trying to figure out how what I need to do in the derived container to perform the root user step down and switch to the
appuser
?Many thanks.