11# Use the latest nginx as the base image
2- FROM nginx:latest
2+ FROM nginx:1.27.3
33
44# Set environment variables
55ENV TEMP_FRONTEND_DIR=/temp-frontend-files
@@ -10,20 +10,30 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]
1010# Create a non-root user and group
1111RUN groupadd -r frontenduser && useradd -r -g frontenduser frontenduser
1212
13+ # Create a directory for the PID file and assign ownership to frontenduser
14+ RUN mkdir -p /var/run/nginx && chown -R frontenduser:frontenduser /var/run/nginx
15+
1316# Copy all files to the container
1417COPY . /usr/share/nginx/html
1518
19+ # Copy nginx.conf to a writable location and modify the PID path
20+ RUN cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.custom && \
21+ sed -i 's|/var/run/nginx.pid|/var/run/nginx/nginx.pid|g' /etc/nginx/nginx.conf.custom
22+
1623# Set ownership of necessary directories
1724RUN chown -R frontenduser:frontenduser /usr/share/nginx/html \
1825 && chown -R frontenduser:frontenduser /var/cache/nginx \
1926 && chown -R frontenduser:frontenduser /var/log/nginx
2027
28+ # Switch to non-root user
29+ USER frontenduser
30+
2131# Expose the default nginx port (80)
2232EXPOSE 80
2333
2434# Add health check for the container
2535HEALTHCHECK --interval=1m --timeout=10s --start-period=30s --retries=3 \
2636 CMD curl -f http://localhost/ || exit 1
2737
28- # Use the default nginx command
29- CMD ["nginx" , "-g" , "daemon off;" ]
38+ # Use the custom nginx.conf during runtime
39+ CMD ["nginx" , "-c" , "/etc/nginx/nginx.conf.custom" , "- g" , "daemon off;" ]
0 commit comments