From 24c2cede3a161b8527f15f10e84b416957d77611 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Wed, 7 Feb 2018 08:44:37 +0200 Subject: [PATCH] Updated post on correct uid in a Docker container. - More corrections. - Seperate case for GNU and BusyBox userland. --- content/docker_uid.rst | 12 +++++++----- content/static/runas | 9 +-------- content/static/runas-busybox | 8 ++++++++ content/static/runas-gnu | 8 ++++++++ 4 files changed, 24 insertions(+), 13 deletions(-) mode change 100755 => 120000 content/static/runas create mode 100755 content/static/runas-busybox create mode 100755 content/static/runas-gnu diff --git a/content/docker_uid.rst b/content/docker_uid.rst index 7542e51..ab8e789 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 1ac6577..0000000 --- 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 0000000..129d4a6 --- /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 0000000..01b3f7d --- /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 0000000..a78926a --- /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" -- "$@" -- GitLab