Refactor Dockerfile to parameterize user and group IDs for enhanced flexibility
- Introduced ARG variables for UID and GID to allow dynamic user and group configuration. - Updated ownership commands to utilize the new UID and GID parameters, improving compatibility with different environments. - Maintained non-root user practices while ensuring proper permissions for Nginx and associated files.
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
# Image officielle « non-root » (nginxinc) : pid, user, port 8080 — on n’imite pas nginx:alpine à coups de sed.
|
||||
# https://github.com/nginxinc/docker-nginx-unprivileged
|
||||
# Même logique que l’image upstream : UID/GID numériques, pas le nom « nginx ».
|
||||
# https://github.com/nginxinc/docker-nginx-unprivileged/blob/main/stable/alpine/Dockerfile
|
||||
FROM nginxinc/nginx-unprivileged:stable-alpine
|
||||
|
||||
ARG UID=101
|
||||
ARG GID=101
|
||||
|
||||
USER root
|
||||
RUN --mount=type=cache,target=/var/cache/apk \
|
||||
apk add --no-cache git
|
||||
@@ -21,16 +24,15 @@ RUN find . -mindepth 1 -delete \
|
||||
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
|
||||
COPY refresh.sh /refresh.sh
|
||||
|
||||
# Même UID que l’image (nginx, 101) ; pas de retouche manuelle de nginx.conf.
|
||||
RUN chmod +x /refresh.sh \
|
||||
&& chown -R nginx:nginx /usr/share/nginx/html /refresh.sh \
|
||||
&& chown -R "${UID}:${GID}" /usr/share/nginx/html /refresh.sh \
|
||||
&& mkdir -p /home/nginx \
|
||||
&& chown nginx:nginx /home/nginx \
|
||||
&& su nginx -s /bin/sh -c 'HOME=/home/nginx git config --global --add safe.directory /usr/share/nginx/html'
|
||||
&& chown "${UID}:${GID}" /home/nginx \
|
||||
&& su "${UID}" -s /bin/sh -c 'HOME=/home/nginx git config --global --add safe.directory /usr/share/nginx/html'
|
||||
|
||||
ENV HOME=/home/nginx
|
||||
|
||||
USER nginx
|
||||
USER ${UID}
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
|
||||
Reference in New Issue
Block a user