docker: support running the container as www-data (uid 33)
Build and Deploy (dev) / build (push) Successful in 4m23s

- Set ownership of storage, bootstrap/cache and public/assets/vendor at
  build time
- Entrypoint only creates/chowns directories when running as root

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
eric.busandClaude Opus 5.5 committed 2026-11-20 14:17:42 +01:00
1 parent 1fdc5559cf
commit da971e1646
2 files changed
+21 -16

No files matched your search

+5 -2
View File
@@ -77,8 +77,11 @@ RUN mkdir -p \
# Generate the optimized autoloader and run composer scripts (package:discover)
RUN composer dump-autoload --no-dev --optimize --no-interaction
# Copy the npm packages into public/assets/vendor
RUN node scripts/setup-vendor.js
# Copy the npm packages into public/assets/vendor, then make the directories
# Laravel writes to owned by www-data, so the container can run as uid 33
RUN node scripts/setup-vendor.js \
&& chown -R www-data:www-data storage bootstrap/cache public/assets/vendor \
&& chmod -R ug+rwX storage bootstrap/cache public/assets/vendor
# Copy and set up entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
+16 -14
View File
@@ -6,13 +6,20 @@ cd /var/www/app
# Set HOME for npm cache (www-data user needs writable cache directory)
export HOME=/tmp
echo "Setting up dependencies..."
WRITABLE_DIRS="storage/framework storage/logs bootstrap/cache public/assets/vendor"
# Create vendor directories and fix permissions
echo "Fixing permissions..."
mkdir -p bootstrap/cache storage/framework storage/logs public/assets/vendor
chown -R www-data:www-data bootstrap/cache storage/framework storage/logs public/assets/vendor
chmod -R ug+rwX bootstrap/cache storage/framework storage/logs public/assets/vendor
# Ownership is already set in the image. Only fix it when running as root,
# e.g. when a root-owned volume is mounted over one of these directories.
# When running as www-data (uid 33) we can't (and don't need to) chown.
fix_permissions() {
if [ "$(id -u)" = "0" ]; then
mkdir -p $WRITABLE_DIRS
chown -R www-data:www-data $WRITABLE_DIRS
chmod -R ug+rwX $WRITABLE_DIRS
fi
}
fix_permissions
# PHP dependencies are installed in the image. Only install them here as a
# fallback, e.g. when the app directory is mounted as a volume without vendor/.
@@ -36,13 +43,8 @@ elif [ -z "$(ls -A public/assets/vendor 2>/dev/null)" ]; then
node scripts/setup-vendor.js
fi
# Fix permissions
echo "Fixing permissions..."
chown -R www-data:www-data \
bootstrap/cache \
public/assets/vendor
# Files created by the fallbacks above may be owned by root
fix_permissions
chmod -R ug+rwX bootstrap/cache
echo "✓ Setup complete, starting Apache..."
echo "Starting Apache..."
exec apache2-foreground