feat: Correct UID in container (same as folder)

This commit is contained in:
Frederik Beimgraben 2025-10-31 00:46:26 +01:00
parent 91ef8ad136
commit 22a6ba51d4
4 changed files with 54 additions and 5 deletions

15
.env.example Normal file
View File

@ -0,0 +1,15 @@
# Docker Environment Configuration Example
# =========================================
# Copy this file to .env and adjust values as needed
# User ID and Group ID for the Docker container user
# These should match your local user to avoid permission issues
# You can get your current values by running:
# echo "HOST_UID=$(id -u)"
# echo "HOST_GID=$(id -g)"
HOST_UID=1000
HOST_GID=1000
# Note: When using 'make docker-build', these values are automatically
# detected and passed to docker-compose, so you don't need a .env file.
# This file is only needed if you run docker-compose directly.

1
.gitignore vendored
View File

@ -38,3 +38,4 @@ Output/
# Ignore chapter backups and Temporary PDF files from Inkscape # Ignore chapter backups and Temporary PDF files from Inkscape
.chapter-backups/ .chapter-backups/
svg-inkscape/ svg-inkscape/
.config/

View File

@ -135,8 +135,8 @@ check-docker:
.PHONY: docker-build .PHONY: docker-build
docker-build: check-docker docker-build: check-docker
@echo -e "$(BLUE)=== Building LaTeX Document with Docker ===$(NC)" @echo -e "$(BLUE)=== Building LaTeX Document with Docker ===$(NC)"
@echo -e "$(YELLOW)→ Starting Docker container...$(NC)" @echo -e "$(YELLOW)→ Starting Docker container with UID=$$(id -u) GID=$$(id -g)...$(NC)"
@$(DOCKER_COMPOSE_CMD) up --build || { \ @HOST_UID=$$(id -u) HOST_GID=$$(id -g) $(DOCKER_COMPOSE_CMD) up --build || { \
echo -e "$(RED)✗ Docker build failed$(NC)"; \ echo -e "$(RED)✗ Docker build failed$(NC)"; \
echo -e "$(YELLOW) Try 'make docker-clean' and rebuild$(NC)"; \ echo -e "$(YELLOW) Try 'make docker-clean' and rebuild$(NC)"; \
exit 1; \ exit 1; \

View File

@ -21,11 +21,21 @@ services:
build: build:
# Build context is the current directory # Build context is the current directory
context: . context: .
# Pass the current directory's UID and GID as build arguments
# These are automatically set by the Makefile, or can be manually provided:
# HOST_UID=$(id -u) HOST_GID=$(id -g) docker-compose up --build
args:
HOST_UID: ${HOST_UID:-1000}
HOST_GID: ${HOST_GID:-1000}
# Inline Dockerfile definition for additional packages # Inline Dockerfile definition for additional packages
dockerfile_inline: | dockerfile_inline: |
# Start from the full TeXLive image (includes XeLaTeX, Biber, etc.) # Start from the full TeXLive image (includes XeLaTeX, Biber, etc.)
FROM texlive/texlive:latest FROM texlive/texlive:latest
# Accept build arguments for the host directory's UID and GID
ARG HOST_UID=1000
ARG HOST_GID=1000
# Update package lists to ensure we get the latest versions # Update package lists to ensure we get the latest versions
RUN apt update -y RUN apt update -y
@ -33,6 +43,32 @@ services:
# Required for processing SVG graphics in the document # Required for processing SVG graphics in the document
RUN apt install inkscape -y RUN apt install inkscape -y
# Create a group with the host directory's GID
# The '|| true' ensures the command succeeds even if the group already exists
RUN groupadd -g ${HOST_GID} texuser 2>/dev/null || true
# Create a user with the host directory's UID and GID
# - Same UID/GID as the host directory to avoid permission issues
# - Home directory at /home/texuser
# - Default shell /bin/bash
# If UID is taken in container, rename the user with the ID ${HOST_UID} to texuser
RUN useradd -m -u ${HOST_UID} -g ${HOST_GID} -s /bin/bash texuser || \
usermod --login texuser "$(id -nu ${HOST_UID})"
# Make /data and chown it to the user
RUN mkdir /data && \
chown -R ${HOST_UID}:${HOST_GID} /data
# Set /data as the user home
RUN usermod -d /data texuser
# Set /data as the working directory
WORKDIR /data
# Set the default user for running commands
# All subsequent commands will run as this user
USER texuser
# Volume mappings # Volume mappings
volumes: volumes:
# Mount the entire project directory to /data in the container # Mount the entire project directory to /data in the container
@ -40,9 +76,6 @@ services:
- ./:/data - ./:/data
# Working directory configuration # Working directory configuration
# Previous project-specific path (kept for reference):
# working_dir: /data/Projektbeschreibung-MKI-METI-Projekt
# Current: Set to /data root for general use
working_dir: /data working_dir: /data
# Default command when container starts # Default command when container starts