From 9becfcc03c8e68a226c82bc514733b5c03535a44 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 13 Oct 2023 19:32:09 +0100 Subject: [PATCH 1/5] bump alpine --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ab66bb0..ba1e995 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.18.2 +FROM alpine:3.18.4 # Install dependencies RUN apk update && \ -- 2.45.2 From fd60603728b98cbaebdd5b749b23eeb5925e973e Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 13 Oct 2023 19:38:54 +0100 Subject: [PATCH 2/5] build nginx from source to use latest version --- Dockerfile | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index ba1e995..d9ce58f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,21 @@ FROM alpine:3.18.4 -# Install dependencies -RUN apk update && \ - apk upgrade && \ - apk add --no-cache nginx php81 php81-fpm php81-gd && \ - rm -rf /var/cache/apk/* +# Install build dependencies and required tools +RUN apk update && apk upgrade && \ + apk add --no-cache php81 php81-fpm php81-gd build-base pcre-dev openssl-dev zlib-dev linux-headers + +# Download and build the latest version of Nginx from source +WORKDIR /tmp +RUN wget https://nginx.org/download/nginx-1.25.2.tar.gz +RUN tar -xzvf nginx-1.25.2.tar.gz +WORKDIR /tmp/nginx-1.25.2 +RUN ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/sbin/nginx +RUN make +RUN make install + +# Cleanup unnecessary files +RUN rm -rf /tmp/* +RUN rm -rf /var/cache/apk/* # Set up nginx COPY ./docker/nginx.conf /etc/nginx/nginx.conf -- 2.45.2 From f342efdabf3254b259835dd30084f9ea52f75cf6 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 13 Oct 2023 19:44:24 +0100 Subject: [PATCH 3/5] fix default nginx page from showing --- Dockerfile | 2 +- docker/start.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d9ce58f..c17b33c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ WORKDIR /tmp RUN wget https://nginx.org/download/nginx-1.25.2.tar.gz RUN tar -xzvf nginx-1.25.2.tar.gz WORKDIR /tmp/nginx-1.25.2 -RUN ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/sbin/nginx +RUN ../configure --prefix=/usr/local/nginx --sbin-path=/usr/local/sbin/nginx --conf-path=/etc/nginx/nginx.conf RUN make RUN make install diff --git a/docker/start.sh b/docker/start.sh index c53aa40..f96a68d 100644 --- a/docker/start.sh +++ b/docker/start.sh @@ -41,7 +41,7 @@ function start() { echo "Starting PHP & Nginx" php-fpm81 && chmod 777 /run/php/php.sock && - nginx -g 'daemon off;' + /usr/local/sbin/nginx -g 'daemon off;' } # Start Nginx and retry if it fails -- 2.45.2 From 19ac61425c7e8e77ba2b01f3fc218f5bb9ccd5f5 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 13 Oct 2023 19:45:43 +0100 Subject: [PATCH 4/5] fix a silly --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c17b33c..02ae516 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ WORKDIR /tmp RUN wget https://nginx.org/download/nginx-1.25.2.tar.gz RUN tar -xzvf nginx-1.25.2.tar.gz WORKDIR /tmp/nginx-1.25.2 -RUN ../configure --prefix=/usr/local/nginx --sbin-path=/usr/local/sbin/nginx --conf-path=/etc/nginx/nginx.conf +RUN ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/sbin/nginx --conf-path=/etc/nginx/nginx.conf RUN make RUN make install -- 2.45.2 From 75bd2407b9455602dac8bef9f35401d9527d0c0a Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 13 Oct 2023 19:48:48 +0100 Subject: [PATCH 5/5] add build steps to make the final image smaller --- Dockerfile | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 02ae516..dc12f73 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 RUN apk update && apk upgrade && \ @@ -15,7 +16,6 @@ RUN make install # Cleanup unnecessary files RUN rm -rf /tmp/* -RUN rm -rf /var/cache/apk/* # Set up nginx 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 ./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 CMD ["sh", "/start.sh"] \ No newline at end of file -- 2.45.2