From 46ce4228a5a91a629152b06aa2f1ca28cbe22ab2 Mon Sep 17 00:00:00 2001 From: Richy HBM Date: Fri, 10 Apr 2026 23:14:18 +0100 Subject: [PATCH] Allow specifying which user the stack files should belong to (#83) Co-authored-by: cmcooper1980 <31871143+cmcooper1980@users.noreply.github.com> --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ backend/stack.ts | 14 ++++++-------- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0aeeb95..ed7b788 100644 --- a/README.md +++ b/README.md @@ -81,9 +81,51 @@ curl "https://dockge.kuma.pet/compose.yaml?port=5001&stacksPath=/opt/stacks" --o - port=`5001` - stacksPath=`/opt/stacks` +ALSO, once compose is generated/downloaded, add the `PUID` and `PGID` section below to your compose `environment:` section to set stack ownership, otherwise default is `root` + +``` + # Both PUID and PGID must be set for it to do anything + - PUID=1000 # Set the stack file/dir ownership to this user + - PGID=1000 # Set the stack file/dir ownership to this group +``` + Interactive compose.yaml generator is available on: https://dockge.kuma.pet +##OR copy and paste your compose from the following: + +If you want to store your stacks in another directory, you can change the `DOCKGE_STACKS_DIR` environment variable and volumes. + +compose: +``` +services: + dockge: + image: louislam/dockge:1 + restart: unless-stopped + ports: + # Host Port:Container Port + - 5001:5001 + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ./data:/app/data + + # If you want to use private registries, you need to share the auth file with Dockge: + # - /root/.docker/:/root/.docker + + # Stacks Directory + # Your stacks directory in the host (The paths inside container must be the same as the host) + # ⚠️ If you did it wrong, your data could end up be written into a wrong path. + # ✔️ CORRECT EXAMPLE: - /my-stacks:/my-stacks (Both paths match) + # ❌ WRONG EXAMPLE: - /docker:/my-stacks (Both paths do not match) + - /opt/stacks:/opt/stacks + environment: + # Tell Dockge where your stacks directory is + - DOCKGE_STACKS_DIR=/opt/stacks + # Both PUID and PGID must be set for it to do anything + - PUID=1000 # Set the stack file/dir ownership to this user + - PGID=1000 # Set the stack file/dir ownership to this group +``` + ## How to Update ```bash diff --git a/backend/stack.ts b/backend/stack.ts index f217696..b26a78a 100644 --- a/backend/stack.ts +++ b/backend/stack.ts @@ -195,14 +195,12 @@ export class Stack { } // Write or overwrite the compose.yaml - await fsAsync.writeFile(path.join(dir, this._composeFileName), this.composeYAML); - - const envPath = path.join(dir, ".env"); - - // Write or overwrite the .env - // If .env is not existing and the composeENV is empty, we don't need to write it - if (await fileExists(envPath) || this.composeENV.trim() !== "") { - await fsAsync.writeFile(envPath, this.composeENV); + fs.writeFileSync(path.join(dir, this._composeFileName), this.composeYAML); + if (process.env.PUID && process.env.PGID) { + const uid = Number(process.env.PUID); + const gid = Number(process.env.PGID); + fs.lchownSync(dir, uid, gid); + fs.chownSync(path.join(dir, this._composeFileName), uid, gid); } }