add build steps to make the final image smaller
All checks were successful
Publish Docker Image / docker (push) Successful in 59s

This commit is contained in:
Lee 2023-10-13 19:48:48 +01:00
parent 19ac61425c
commit 75bd2407b9

@ -1,4 +1,5 @@
FROM alpine:3.18.4 # Stage 1: Build Nginx
FROM alpine:3.18.4 as builder
# Install build dependencies and required tools # Install build dependencies and required tools
RUN apk update && apk upgrade && \ RUN apk update && apk upgrade && \
@ -15,7 +16,6 @@ RUN make install
# Cleanup unnecessary files # Cleanup unnecessary files
RUN rm -rf /tmp/* RUN rm -rf /tmp/*
RUN rm -rf /var/cache/apk/*
# Set up nginx # Set up nginx
COPY ./docker/nginx.conf /etc/nginx/nginx.conf COPY ./docker/nginx.conf /etc/nginx/nginx.conf
@ -24,5 +24,22 @@ COPY ./docker/nginx.conf /etc/nginx/nginx.conf
COPY ./upload.php /tmp/upload.php COPY ./upload.php /tmp/upload.php
COPY ./docker/start.sh /start.sh COPY ./docker/start.sh /start.sh
# Stage 2: Create a smaller image
FROM alpine:3.18.4
# Copy Nginx and PHP-FPM binaries and configurations from the builder stage
COPY --from=builder /usr/local/nginx /usr/local/nginx
COPY --from=builder /etc/nginx /etc/nginx
COPY --from=builder /etc/php81 /etc/php81
COPY --from=builder /tmp/upload.php /tmp/upload.php
COPY --from=builder /start.sh /start.sh
# Install runtime dependencies
RUN apk update && apk upgrade && \
apk add --no-cache php81 php81-fpm php81-gd
# Cleanup unnecessary files
RUN rm -rf /var/cache/apk/*
# Start server # Start server
CMD ["sh", "/start.sh"] CMD ["sh", "/start.sh"]