Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
#!/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" -- "$@"
runas-gnu
\ No newline at end of file
#!/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" -- "$@"
#!/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" -- "$@"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment