Community maintained Docker config for the knot server

Add UID and GID arguments to Dockerfile #6

deleted opened by ionchy.ca targeting main from ionchy.ca/knot-docker: main

This lets you specify the UID and GID of the git user during build. The repository and app directories are owned by this git user.

typo

another typo

I swear the Dockerfile itself is correct I am just typoing the README

Labels

None yet.

Participants 4
AT URI
at://did:plc:ypsrm6ue6o5xk5kvbdhwtppm/sh.tangled.repo.pull/3ly6z4onsfx22
+17 -1
Diff #0
+6 -1
Dockerfile
··· 20 20 label org.opencontainers.image.vendor='tangled.sh' 21 21 label org.opencontainers.image.licenses='MIT' 22 22 23 + arg UID=1000 24 + arg GID=1000 25 + 23 26 copy rootfs . 24 27 run chmod 755 /etc 25 28 run chmod -R 755 /etc/s6-overlay 26 29 run apk add shadow s6-overlay execline openssl openssh git curl bash 27 - run useradd -d /home/git git && openssl rand -hex 16 | passwd --stdin git 30 + run groupadd -g $GID -f git 31 + run useradd -u $UID -g $GID -d /home/git git 32 + run openssl rand -hex 16 | passwd --stdin git 28 33 run mkdir -p /home/git/repositories && chown -R git:git /home/git 29 34 copy --from=builder /usr/bin/knot /usr/bin 30 35 run mkdir /app && chown -R git:git /app
+11
readme.md
··· 29 29 The command above for example will build the latest commit on the `master` 30 30 branch. 31 31 32 + By default it will also create a `git` user with user and group ID 1000:1000, 33 + but you can change it with the `UID` and `GID` build arguments. 34 + 35 + ```sh 36 + docker build -t knot:latest --build-arg UID=$(id -u) GID=$(id -g) 37 + ``` 38 + 39 + The command above for example will create a user with the host user's UID and GID. 40 + This is useful if you are bind mounting the repositories and app folder on the host, 41 + as in the provided `docker-compose.yml` file. 42 + 32 43 <hr style="margin-bottom: 20px; margin-top: 10px" /> 33 44 34 45 When using compose, it can be specified as a build argument which will be

Submissions

sign up or login to add to the discussion
ionchy.ca submitted #1
1 commit
expand
Add UID and GID arguments to Dockerfile
ionchy.ca

Sorry for the duplicate PR with #4 and changeless resubmissions lol I'm experimenting with jujutsu and stacked PRs I thought editing the description in past commits would have them show up in the PR but I guess not. I've pasted them down below for reference:

  • #5: I couldn't push or pull from any repositories until I set -git-dir following the instructions in knot-hosting, so this adds the /etc/ssh/sshd_config.d/authorized_keys_command.conf file to rootfs.
  • #6: UID and GID args can now be set during build, so following the example command in the README should fix #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.
krasovs.ky

What is the use case you are trying to solve with that?

krasovs.ky

Oh, I am dumb, I didn't notice the issue #2.

knotbin.com

@ionchy.ca This looks great! Just make sure to also add the UID and GID parameters to the environment in the docker compose as well for people building with Docker Compose.

ionchy.ca

I've updated the Docker Compose file and the README but I still don't know how to debug why resubmitting the PR doesn't work so I'm just going to create a new one

ionchy.ca

Ok, new PR created at #9

This pull has been deleted (possibly by jj abandon or jj squash)
ionchy.ca submitted #0
1 commit
expand
Add UID and GID arguments to Dockerfile

I would still combine these into a single RUN line, joined with &&. Each command in a dockerfile creates a new layer in the image, which bloats this more than necessary. More of a best-practice than an actual problem.

ionchy.ca

So that would be joining all three of the groupadd, useradd, and openssl lines?