Skip to content
Snippets Groups Projects

runas

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by nimrod

    Docker entrypoint script to run with the correct user. See https://www.shore.co.il/blog/docker_uid/ .

    runas 358 B
    #!/bin/sh
    set -eu
    
    [ "$(id -u)" = "0" ] || { echo "Not running as root, continuing as the current user."; eval exec "$@"; }
    command -v stat > /dev/null || { echo "Can't find stat, exiting."; exit 1; }
    command -v gosu > /dev/null || { echo "Can't find gosu, exiting."; exit 1; }
    uid="$(stat . -c '%u')"
    gid="$(stat . -c '%g')"
    eval exec gosu "$uid:$gid" "$@"
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment