Commit 24c2cede authored by nimrod's avatar nimrod
Browse files

Updated post on correct uid in a Docker container.

- More corrections.
- Seperate case for GNU and BusyBox userland.
parent 9cd485f7
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -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

content/static/runas

deleted100755 → 0
+1 −8
Original line number Diff line number Diff line
#!/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" -- "$@"

content/static/runas

0 → 120000
+1 −8
Original line number Diff line number Diff line
runas-gnu
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
#!/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" -- "$@"
+8 −0
Original line number Diff line number Diff line
#!/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" -- "$@"

content/static/runas

100755 → 120000
+1 −8

File changed.File mode changed from 100755 to 120000.

Contains only whitespace changes.