From b5120790a4942caf8e10fe236c76fa69d314167a Mon Sep 17 00:00:00 2001 From: Jonathan Chan Date: Sat, 6 Sep 2025 02:45:24 +0200 Subject: [PATCH] Add `UID` and `GID` arguments to Dockerfile Change-Id: pqwwuswvnlxvspzkrxrkuokorlvvkpxn `UID` and `GID` args can now be set during build, so following the example command in the README should fix [#2](https://tangled.sh/@tangled.sh/knot-docker/issues/2) by providing a `UID` and `GID` that exist on the host so that the directories owned by git in the container can be bind mounted on the host. --- Dockerfile | 7 ++++++- docker-compose.yml | 6 +++++- readme.md | 18 ++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4aab26b..610cbcb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,11 +20,16 @@ label org.opencontainers.image.url='https://tangled.sh' label org.opencontainers.image.vendor='tangled.sh' label org.opencontainers.image.licenses='MIT' +arg UID=1000 +arg GID=1000 + copy rootfs . run chmod 755 /etc run chmod -R 755 /etc/s6-overlay run apk add shadow s6-overlay execline openssl openssh git curl bash -run useradd -d /home/git git && openssl rand -hex 16 | passwd --stdin git +run groupadd -g $GID -f git +run useradd -u $UID -g $GID -d /home/git git +run openssl rand -hex 16 | passwd --stdin git run mkdir -p /home/git/repositories && chown -R git:git /home/git copy --from=builder /usr/bin/knot /usr/bin run mkdir /app && chown -R git:git /app diff --git a/docker-compose.yml b/docker-compose.yml index 0ac7811..69b34b7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,10 @@ services: knot: - build: . + build: + context: . + args: + UID: 1000 + GID: 1000 environment: KNOT_SERVER_HOSTNAME: ${KNOT_SERVER_HOSTNAME} KNOT_SERVER_OWNER: ${KNOT_SERVER_OWNER} diff --git a/readme.md b/readme.md index d77f4aa..a39d6de 100644 --- a/readme.md +++ b/readme.md @@ -29,15 +29,29 @@ docker build -t knot:latest --build-arg TAG=master . The command above for example will build the latest commit on the `master` branch. +By default it will also create a `git` user with user and group ID 1000:1000, +but you can change it with the `UID` and `GID` build arguments. + +```sh +docker build -t knot:latest --build-arg UID=$(id -u) GID=$(id -g) +``` + +The command above for example will create a user with the host user's UID and GID. +This is useful if you are bind mounting the repositories and app folder on the host, +as in the provided `docker-compose.yml` file. +
-When using compose, it can be specified as a build argument which will be +When using compose, these can be specified as build arguments which will be passed to the builder. ```yaml build: context: . - args: { TAG: master } + args: + TAG: master + UID: 1000 + GID: 1000 ``` This will for example tell docker to build it using the `master` branch like -- 2.51.0