Skip to content

Modern Docker Management, Designed for Everyone

fix: dockerfile and docker socket permissions

Kyle Mendell3b1359df3841
diff --git a/Dockerfile b/Dockerfile
index a72762b35..984e80d8b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,67 +1,54 @@
-# ---- Base Node ----
-# Use a specific Node.js version on Alpine for smaller images
-FROM node:22-alpine AS base
+# Stage 1: Build the application
+FROM node:22-alpine AS builder
WORKDIR /app
-# Copy package.json and lock file separately to leverage Docker cache
-COPY package.json package-lock.json* ./
-
-# ---- Dependencies ----
-# Install only production dependencies first
-FROM base AS prod-deps
-RUN npm install --omit=dev
-
-# ---- Build ----
-# Install all dependencies (including dev) and build the app
-FROM base AS builder
-# Copy production node_modules from the previous stage
-COPY --from=prod-deps /app/node_modules ./node_modules
-# Install dev dependencies needed for build
+RUN mkdir -p /app/data && chown node:node /app/data
+COPY package*.json ./
RUN npm install
-# Copy the rest of the application source code
COPY . .
-# Run the SvelteKit build command
+RUN npm ci
RUN npm run build
-# ---- Runner ----
-# Use a clean Node.js Alpine image for the final stage
-FROM node:22-alpine AS runner
-WORKDIR /app
+# Stage 2: Production image
+FROM node:22-alpine
-# Install su-exec (needed by the entrypoint script) and bash (often useful for scripts)
-RUN apk add --no-cache su-exec bash
+# Delete default node user
+RUN deluser --remove-home node
-# Set environment variables
-ENV NODE_ENV=production
-# Set HOST for adapter-node to listen on all interfaces within the container
-ENV HOST=0.0.0.0
-# Set PORT (optional, adapter-node defaults to 3000 if not set)
-# ENV PORT=3000
-# Default PUID/PGID (can be overridden in docker-compose.yml)
-ENV PUID=1000
-ENV PGID=1000
+# Install necessary packages
+RUN apk add --no-cache su-exec curl shadow
-# Copy necessary artifacts from previous stages
-# Copy production dependencies
-COPY --from=prod-deps /app/node_modules ./node_modules
-# Copy the built application output
-COPY --from=builder /app/build ./build
-# Copy package.json (needed by adapter-node runner)
-COPY --from=builder /app/package.json ./package.json
-# Copy the settings file if it exists at build time (optional, usually mounted as a volume)
-# COPY --from=builder /app/app-settings.json ./app-settings.json
+WORKDIR /app
-# Copy the entrypoint script and make it executable
+# Copy entrypoint script
COPY scripts/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
-# NOTE: User creation and ownership changes are now handled by the entrypoint script
-# We run as root initially, and the entrypoint script switches user
+# Copy application files
+COPY --from=builder /app/build ./build
+COPY package*.json ./
+RUN npm install --omit=dev
+COPY --from=builder /app/static ./static
+
+# Create docker group with same GID as the host (typically 998 or 999)
+# We'll use 998 which is common, but this can be overridden at runtime
+ENV DOCKER_GID=998
+RUN addgroup -g ${DOCKER_GID} docker
+
+# Create arcane user/group
+ENV PUID=1000
+ENV PGID=1000
+RUN addgroup -g ${PGID} arcane && \
+ adduser -D -u ${PUID} -G arcane arcane && \
+ # Add arcane user to docker group to allow socket access
+ adduser arcane docker && \
+ # Set ownership of app files
+ chown -R arcane:arcane /app
-# Expose the port the application runs on (default for adapter-node is 3000)
EXPOSE 3000
+LABEL org.opencontainers.image.authors="kmendell"
-# Set the entrypoint
-ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
+# Add volume for persistent data
+VOLUME ["/app/data"]
-# Command to start the Node.js server (passed as arguments to the entrypoint)
+ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["node", "build"]
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
index 1ca82e7f8..39e1b0aa9 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,35 +1,18 @@
services:
arcane:
- # Build the image using the Dockerfile in the current directory (.)
image: ghcr.io/ofkm/arcane:latest
container_name: arcane
ports:
- # Map host port 5173 to the container's exposed port 3000
- "3000:3000"
volumes:
- # Mount the Docker socket to allow Arcane to interact with the Docker Engine
- - /var/run/docker.sock:/var/run/docker.sock:ro # Read-only is often safer if Arcane only needs to read info
-
- # Optional: Mount a volume to persist the settings file outside the container
- # Create a directory named 'arcane-data' in the same directory as this compose file
- # The entrypoint script will ensure correct permissions if PUID/PGID are set
- - ./arcane-data:/app # Mount the data directory to the app's root
- # Note: If you mount /app, ensure app-settings.json is within this mount
- # Or mount specifically the settings file:
+ - /var/run/docker.sock:/var/run/docker.sock
+ - ./arcane-data:/app/data
# - ./arcane-data/app-settings.json:/app/app-settings.json
environment:
- # Set the User and Group ID for file permissions.
- # The entrypoint script will use these to set ownership.
- # Use 'id -u' and 'id -g' on your host machine to find your user/group ID.
- PUID=1000
- PGID=1000
- # NODE_ENV is already set in the Dockerfile, but can be overridden here if needed
- # - NODE_ENV=production
- # PORT is already set in the Dockerfile (defaults to 3000), override if needed
- # - PORT=3000
- # HOST is already set in the Dockerfile (0.0.0.0)
- # - HOST=0.0.0.0
+ - DOCKER_GID=998 # getent group docker | cut -d: -f3
restart: unless-stopped
# Optional: Define the volume if you want Docker to manage it
diff --git a/scripts/docker/entrypoint.sh b/scripts/docker/entrypoint.sh
index aa10fbe02..de18716c1 100644
--- a/scripts/docker/entrypoint.sh
+++ b/scripts/docker/entrypoint.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
# Exit immediately if a command exits with a non-zero status.
set -e
@@ -13,50 +13,66 @@ echo "Entrypoint: Running as root. Setting up user and permissions..."
# Default PUID/PGID if not provided
PUID=${PUID:-1000}
PGID=${PGID:-1000}
+DOCKER_GID=${DOCKER_GID:-998}
APP_USER="arcane"
-APP_GROUP="arcane-group"
+APP_GROUP="arcane"
APP_DIR="/app"
-# Optional: Define a data directory if you mount volumes for settings/data
-# DATA_DIR="/app/data"
-echo "Entrypoint: Using PUID=${PUID}, PGID=${PGID}"
+echo "Entrypoint: Using PUID=${PUID}, PGID=${PGID}, DOCKER_GID=${DOCKER_GID}"
-# Create the group if it doesn't exist
+# Create the arcane group if it doesn't exist
if ! getent group "$PGID" > /dev/null 2>&1; then
echo "Entrypoint: Creating group ${APP_GROUP} with GID ${PGID}..."
addgroup -g "$PGID" "$APP_GROUP"
else
# If group with PGID exists, find its name
- APP_GROUP=$(getent group "$PGID" | cut -d: -f1)
- echo "Entrypoint: Group with GID ${PGID} already exists: ${APP_GROUP}"
+ GROUP_NAME=$(getent group "$PGID" | cut -d: -f1)
+ echo "Entrypoint: Group with GID ${PGID} already exists: ${GROUP_NAME}"
fi
-# Create the user if it doesn't exist
+# Ensure the docker group exists with correct GID
+if ! getent group docker > /dev/null 2>&1; then
+ echo "Entrypoint: Creating docker group with GID ${DOCKER_GID}..."
+ addgroup -g "$DOCKER_GID" docker
+else
+ CURRENT_DOCKER_GID=$(getent group docker | cut -d: -f3)
+ if [ "$CURRENT_DOCKER_GID" != "$DOCKER_GID" ]; then
+ echo "Entrypoint: Updating docker group from GID ${CURRENT_DOCKER_GID} to ${DOCKER_GID}..."
+ groupmod -g "$DOCKER_GID" docker
+ fi
+fi
+
+# Create the arcane user if it doesn't exist
if ! getent passwd "$PUID" > /dev/null 2>&1; then
echo "Entrypoint: Creating user ${APP_USER} with UID ${PUID}..."
- adduser -D -u "$PUID" -G "$APP_GROUP" -h "$APP_DIR" -s /bin/bash "$APP_USER"
+ adduser -D -u "$PUID" -G "$APP_GROUP" "$APP_USER"
else
# If user with PUID exists, find their name
- APP_USER=$(getent passwd "$PUID" | cut -d: -f1)
- echo "Entrypoint: User with UID ${PUID} already exists: ${APP_USER}"
- # Ensure the existing user is part of the target group
- if ! id -nG "$APP_USER" | grep -qw "$APP_GROUP"; then
- echo "Entrypoint: Adding existing user ${APP_USER} to group ${APP_GROUP}..."
- addgroup "$APP_USER" "$APP_GROUP"
+ USERNAME=$(getent passwd "$PUID" | cut -d: -f1)
+ echo "Entrypoint: User with UID ${PUID} already exists: ${USERNAME}"
+ # Rename user if it's not the expected name
+ if [ "$USERNAME" != "$APP_USER" ]; then
+ echo "Entrypoint: Renaming user from ${USERNAME} to ${APP_USER}..."
+ usermod -l "$APP_USER" "$USERNAME"
fi
fi
+# Ensure arcane user is in the docker group
+if ! id -nG "$APP_USER" | grep -qw "docker"; then
+ echo "Entrypoint: Adding ${APP_USER} to the docker group..."
+ addgroup "$APP_USER" docker
+fi
+
+# Fix permissions for the Docker socket if it exists
+if [ -e "/var/run/docker.sock" ]; then
+ echo "Entrypoint: Setting permissions for Docker socket..."
+ chmod 666 /var/run/docker.sock
+fi
+
# Change ownership of application directories
echo "Entrypoint: Ensuring ownership of ${APP_DIR} for ${PUID}:${PGID}..."
-# Use chown -R for simplicity on the main app directory
chown -R "$PUID":"$PGID" "$APP_DIR"
-# Optional: Change ownership of a separate data directory if used
-# if [ -d "$DATA_DIR" ]; then
-# echo "Entrypoint: Ensuring ownership of ${DATA_DIR} for ${PUID}:${PGID}..."
-# chown -R "$PUID":"$PGID" "$DATA_DIR"
-# fi
-
-# Execute the command passed to the script (CMD) as the specified user/group
+# Execute the command passed to the script (CMD) as the specified user
echo "Entrypoint: Switching to user ${APP_USER} (${PUID}:${PGID}) and executing command: $@"
-exec su-exec "$PUID":"$PGID" "$@"
+exec su-exec "$APP_USER" "$@"
diff --git a/svelte.config.js b/svelte.config.js
index 415a6c33a..197c453f8 100644
--- a/svelte.config.js
+++ b/svelte.config.js
@@ -1,9 +1,18 @@
-import adapter from '@sveltejs/adapter-node';
-import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
+import adapter from "@sveltejs/adapter-node";
+import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
const config = {
- preprocess: vitePreprocess(),
- kit: { adapter: adapter() }
+ preprocess: vitePreprocess(),
+ kit: {
+ // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
+ // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
+ // See https://kit.svelte.dev/docs/adapters for more information about adapters.
+ adapter: adapter({
+ out: "build",
+ precompress: false,
+ polyfill: true,
+ }),
+ },
};
export default config;