Skip to content
This repository was archived by the owner on Jan 7, 2026. It is now read-only.

Commit da6da08

Browse files
authored
Always use www-data user (Reassign to use PUID/PGID if specified) (#231)
1 parent 2bab01b commit da6da08

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LABEL maintainer="lycheeorg"
66
# Environment variables
77
ENV PUID='1000'
88
ENV PGID='1000'
9-
ENV USER='lychee'
109
ENV PHP_TZ=UTC
1110

1211
# Arguments
@@ -60,8 +59,6 @@ RUN \
6059
composer \
6160
ghostscript \
6261
unzip && \
63-
addgroup --gid "$PGID" "$USER" && \
64-
adduser --gecos '' --no-create-home --disabled-password --uid "$PUID" --gid "$PGID" "$USER" && \
6562
cd /var/www/html && \
6663
sed -i 's/<policy domain="coder" rights="none" pattern="PDF" \/>/<policy domain="coder" rights="read|write" pattern="PDF" \/>/g' /etc/ImageMagick-6/policy.xml && \
6764
if [ "$TARGET" = "release" ] ; then RELEASE_TAG="-b v$(curl -s https://raw.githubusercontent.com/LycheeOrg/Lychee/master/version.md)" ; \
@@ -83,6 +80,8 @@ RUN \
8380
rm storage/framework/sessions/* 2> /dev/null || true && \
8481
rm storage/framework/views/* 2> /dev/null || true && \
8582
rm storage/logs/* 2> /dev/null || true && \
83+
usermod -o -u "$PUID" "www-data" && \
84+
groupmod -o -g "$PGID" "www-data" && \
8685
chown -R www-data:www-data /var/www/html/Lychee && \
8786
chmod -R g+ws storage/image-jobs || true && \
8887
chmod -R g+ws storage/livewire-tmp || true && \

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ Some variables are specific to Docker, and the default values are :
129129

130130
* `PUID=1000`
131131
* `PGID=1000`
132-
* `USER=lychee`
133132
* `PHP_TZ=UTC`
134133
* `STARTUP_DELAY=0`
135134

entrypoint.sh

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ echo "**** Create the symbolic link for the /lychee-tmp folder ****"
6666
rm -r /var/www/html/Lychee/storage/tmp && \
6767
ln -s /lychee-tmp /var/www/html/Lychee/storage/tmp
6868

69+
echo "**** Create user and use PUID/PGID ****"
70+
PUID=${PUID:-1000}
71+
PGID=${PGID:-1000}
72+
if [ ! "$(id -u "www-data")" -eq "$PUID" ]; then usermod -o -u "$PUID" "www-data" ; fi
73+
if [ ! "$(id -g "www-data")" -eq "$PGID" ]; then groupmod -o -g "$PGID" "www-data" ; fi
74+
echo -e " \tUser UID :\t$(id -u "www-data")"
75+
echo -e " \tUser GID :\t$(id -g "www-data")"
76+
6977
cd /var/www/html/Lychee
7078

7179
if [ "$DB_CONNECTION" = "sqlite" ] || [ -z "$DB_CONNECTION" ]
@@ -135,15 +143,6 @@ touch -a /conf/custom.js
135143
rm /var/www/html/Lychee/public/dist/custom.js && \
136144
ln -s /conf/custom.js /var/www/html/Lychee/public/dist/custom.js
137145

138-
echo "**** Create user and use PUID/PGID ****"
139-
PUID=${PUID:-1000}
140-
PGID=${PGID:-1000}
141-
if [ ! "$(id -u "$USER")" -eq "$PUID" ]; then usermod -o -u "$PUID" "$USER" ; fi
142-
if [ ! "$(id -g "$USER")" -eq "$PGID" ]; then groupmod -o -g "$PGID" "$USER" ; fi
143-
echo -e " \tUser UID :\t$(id -u "$USER")"
144-
echo -e " \tUser GID :\t$(id -g "$USER")"
145-
usermod -a -G "$USER" www-data
146-
147146
echo "**** Make sure Laravel's log exists ****" && \
148147
touch /logs/laravel.log
149148

@@ -152,10 +151,8 @@ if [ -n "$SKIP_PERMISSIONS_CHECKS" ] && [ "${SKIP_PERMISSIONS_CHECKS,,}" = "yes"
152151
else
153152
echo "**** Set Permissions ****"
154153
# Set ownership of directories, then files and only when required. See LycheeOrg/Lychee-Docker#120
155-
find /sym /uploads /logs /lychee-tmp -type d \( ! -user "$USER" -o ! -group "$USER" \) -exec chown -R "$USER":"$USER" \{\} \;
156-
find /conf/.env /sym /uploads /logs /lychee-tmp \( ! -user "$USER" -o ! -group "$USER" \) -exec chown "$USER":"$USER" \{\} \;
157-
# Laravel needs to be able to chmod user.css and custom.js for no good reason
158-
find /conf/user.css /conf/custom.js /logs/laravel.log \( ! -user "www-data" -o ! -group "$USER" \) -exec chown www-data:"$USER" \{\} \;
154+
find /var/www/html/Lychee /sym /uploads /logs /lychee-tmp -type d \( ! -user "www-data" -o ! -group "www-data" \) -exec chown -R "www-data":"www-data" \{\} \;
155+
find /conf/.env /sym /uploads /logs /lychee-tmp /conf/user.css /conf/custom.js /logs/laravel.log \( ! -user "www-data" -o ! -group "www-data" \) -exec chown "www-data":"www-data" \{\} \;
159156
find /sym /uploads /logs /lychee-tmp -type d \( ! -perm -ug+w -o ! -perm -ugo+rX -o ! -perm -g+s \) -exec chmod -R ug+w,ugo+rX,g+s \{\} \;
160157
find /conf/user.css /conf/custom.js /conf/.env /sym /uploads /logs /lychee-tmp \( ! -perm -ug+w -o ! -perm -ugo+rX \) -exec chmod ug+w,ugo+rX \{\} \;
161158
fi

0 commit comments

Comments
 (0)