diff --git a/content/docker_uid.rst b/content/docker_uid.rst index 7542e51ae9fa9f2bca0846938518d21b509955d0..ab8e7899c376435fc462d0178234a9884b2bd712 100644 --- a/content/docker_uid.rst +++ b/content/docker_uid.rst @@ -42,20 +42,22 @@ commands. uid="$(stat . --format '%u')" gid="$(stat . --format '%g')" groupadd --force --non-unique --gid "$gid" builder - useradd --non-unique --gid "$gid" --home-dir /volume --no-create-home --shell /bin/sh builder + useradd --non-unique --uid "$uid" --gid "$gid" --home-dir /volume --no-create-home --shell /bin/bash builder sudo -Eu "#$uid" -g "#$gid" -- "$@" The script is also available for `download -<https://www.shore.co.il/blog/static/runas>`_. The only dependency is -:code:`sudo`. You can download it and check to your VCS and incorporate it into -your Dockerfile, or download it via the :code:`ADD` directive, like so: +<https://www.shore.co.il/blog/static/runas-gnu>`_. The only dependency is +:code:`sudo`. There's also a `version +<https://www.shore.co.il/blog/static/runas-busybox>`_ for images using BusyBox +(like Alpine). You can download and check it to your VCS and incorporate it +into your Dockerfile, or download it via the :code:`ADD` directive, like so: .. code:: shell FROM debian:stable RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y sudo build-essential - ADD [ "https://www.shore.co.il/blog/static/runas", "/entrypoint"] + ADD [ "https://www.shore.co.il/blog/static/runas-gnu", "/entrypoint"] ENTRYPOINT [ "/bin/sh", "/entrypoint" ] VOLUME /volume WORKDIR /volume diff --git a/content/static/runas b/content/static/runas deleted file mode 100755 index 1ac6577b0ed37cb9f99bcc15296595f7f5012777..0000000000000000000000000000000000000000 --- a/content/static/runas +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -set -eu -command -v sudo > /dev/null || { echo "Can't find sudo, exiting."; exit 1; } -uid="$(stat . --format '%u')" -gid="$(stat . --format '%g')" -groupadd --force --non-unique --gid "$gid" builder -useradd --non-unique --gid "$gid" --home-dir /volume --no-create-home --shell /bin/sh builder -sudo -Eu "#$uid" -g "#$gid" -- "$@" diff --git a/content/static/runas b/content/static/runas new file mode 120000 index 0000000000000000000000000000000000000000..129d4a6613ef97bf918ee2e0c8eb57fb15431172 --- /dev/null +++ b/content/static/runas @@ -0,0 +1 @@ +runas-gnu \ No newline at end of file diff --git a/content/static/runas-busybox b/content/static/runas-busybox new file mode 100755 index 0000000000000000000000000000000000000000..01b3f7deecd523e16ce972cf3c38e4a322c60b49 --- /dev/null +++ b/content/static/runas-busybox @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu +command -v sudo > /dev/null || { echo "Can't find sudo, exiting."; exit 1; } +uid="$(stat . -c '%u')" +gid="$(stat . -c '%g')" +addgroup -g "$gid" builder +adduser -h /volume -s /bin/sh -G builder -u "$uid" -H -D builder +sudo -Eu "#$uid" -g "#$gid" -- "$@" diff --git a/content/static/runas-gnu b/content/static/runas-gnu new file mode 100755 index 0000000000000000000000000000000000000000..a78926aef24fcf07f355a3a6eb5cbcd065f9e6ac --- /dev/null +++ b/content/static/runas-gnu @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu +command -v sudo > /dev/null || { echo "Can't find sudo, exiting."; exit 1; } +uid="$(stat . --format '%u')" +gid="$(stat . --format '%g')" +groupadd --force --non-unique --gid "$gid" builder +useradd --non-unique --uid "$uid" --gid "$gid" --home-dir /volume --no-create-home --shell /bin/bash builder +sudo -Eu "#$uid" -g "#$gid" -- "$@"