From f887359156724b4ea5a170d0ccb3827117cdaada Mon Sep 17 00:00:00 2001 From: tbreuss Date: Mon, 14 Apr 2025 05:51:28 +0200 Subject: [PATCH 1/4] tryout --- Dockerfile | 63 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 87e06fc..c30cb99 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,64 @@ -ARG PHP_IMAGE=7.4-alpine +ARG PHP_IMAGE=8.1-alpine FROM php:${PHP_IMAGE} -ENV docroot="." +ENV DOCUMENT_ROOT="." EXPOSE 8000 VOLUME [ "/root-dir" ] -# see https://github.com/php/php-src/blob/PHP-7.4/UPGRADING#L766-L775 -# with PHP-7.4+ "docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/" -# has changed to "docker-php-ext-configure gd --with-freetype --with-jpeg" +# See https://github.com/joseluisq/alpine-php-fpm/tree/master/8.1-fpm -RUN apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS \ - && apk --no-cache add --virtual .ext-deps freetype-dev libjpeg-turbo-dev libpng-dev icu-dev \ - && docker-php-ext-configure gd --with-freetype --with-jpeg \ - && docker-php-ext-install gd mysqli pdo pdo_mysql intl \ - && pecl install -o -f xdebug \ +# Install build dependencies +RUN set -eux \ + && apk add --no-cache --update linux-headers --virtual .build-deps $PHPIZE_DEPS \ + freetype-dev \ + libjpeg-turbo-dev \ + libpng-dev \ + libwebp-dev \ + icu-dev \ + libxpm-dev \ + && true + +# Install PHP extensions +RUN set -eux \ + \ + # Install gd + && ln -s /usr/lib/$(apk --print-arch)-linux-gnu/libXpm.* /usr/lib/ \ + && docker-php-ext-configure gd \ + --enable-gd \ + --with-webp \ + --with-jpeg \ + --with-xpm \ + --with-freetype \ + --enable-gd-jis-conv \ + && docker-php-ext-install -j$(nproc) gd \ + \ + # Install intl + && docker-php-ext-install -j$(nproc) intl \ + \ + # Install mysqli + && docker-php-ext-install -j$(nproc) mysqli \ + \ + # Install pdo + && docker-php-ext-install -j$(nproc) pdo \ + && docker-php-ext-install -j$(nproc) pdo_mysql \ + \ + # Install xdebug + && pecl install xdebug \ && docker-php-ext-enable xdebug \ - && apk del .phpize-deps \ - && rm -rf /tmp/pear + \ + # Clean up build dependencies + && docker-php-source delete \ + && apk del .build-deps \ + && rm -rf /tmp/* \ + && true -COPY xdebug.ini $PHP_INI_DIR/conf.d/ +# Install composer +COPY --from=composer /usr/bin/composer /usr/bin/composer COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh ENTRYPOINT ["entrypoint.sh"] -CMD php -S 0.0.0.0:8000 -t $docroot +CMD php -S 0.0.0.0:8000 -t $DOCUMENT_ROOT From 1ebf4f0c99e7ff878c645191c18c24e9cc0affa1 Mon Sep 17 00:00:00 2001 From: tbreuss Date: Mon, 14 Apr 2025 06:47:39 +0200 Subject: [PATCH 2/4] multi stage build --- Dockerfile | 27 +++++++++++++++++++-------- index.php | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 index.php diff --git a/Dockerfile b/Dockerfile index c30cb99..43a9198 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,18 @@ -ARG PHP_IMAGE=8.1-alpine -FROM php:${PHP_IMAGE} +ARG PHP_VERSION="8.1" -ENV DOCUMENT_ROOT="." +FROM php:${PHP_VERSION}-alpine as base -EXPOSE 8000 +RUN set -eux && apk update --no-cache -VOLUME [ "/root-dir" ] + +FROM base as build # See https://github.com/joseluisq/alpine-php-fpm/tree/master/8.1-fpm # Install build dependencies RUN set -eux \ - && apk add --no-cache --update linux-headers --virtual .build-deps $PHPIZE_DEPS \ + && apk add --no-cache --update --virtual .build-deps $PHPIZE_DEPS \ + linux-headers \ freetype-dev \ libjpeg-turbo-dev \ libpng-dev \ @@ -54,11 +55,21 @@ RUN set -eux \ && rm -rf /tmp/* \ && true -# Install composer + +FROM base as target + +ENV DOCUMENT_ROOT="." + +EXPOSE 80 + +VOLUME [ "/root-dir" ] + COPY --from=composer /usr/bin/composer /usr/bin/composer +COPY --from=build /usr/local/lib/php/extensions/* /usr/local/lib/php/extensions +COPY --from=build /usr/local/etc/php/conf.d/* /usr/local/lib/php/conf.d COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh ENTRYPOINT ["entrypoint.sh"] -CMD php -S 0.0.0.0:8000 -t $DOCUMENT_ROOT +CMD php -S 0.0.0.0:80 -t $DOCUMENT_ROOT diff --git a/index.php b/index.php new file mode 100644 index 0000000..c4837a3 --- /dev/null +++ b/index.php @@ -0,0 +1 @@ + Date: Mon, 14 Apr 2025 07:16:17 +0200 Subject: [PATCH 3/4] copy php.ini --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 43a9198..223c114 100644 --- a/Dockerfile +++ b/Dockerfile @@ -67,6 +67,7 @@ VOLUME [ "/root-dir" ] COPY --from=composer /usr/bin/composer /usr/bin/composer COPY --from=build /usr/local/lib/php/extensions/* /usr/local/lib/php/extensions COPY --from=build /usr/local/etc/php/conf.d/* /usr/local/lib/php/conf.d +RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh From 4bca7e60203f7c05830c5bb0e41d0909dc98a66c Mon Sep 17 00:00:00 2001 From: tbreuss Date: Wed, 16 Apr 2025 15:23:53 +0200 Subject: [PATCH 4/4] use json notation for CMD --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 223c114..87f3fae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG PHP_VERSION="8.1" +ARG PHP_VERSION="8.3" FROM php:${PHP_VERSION}-alpine as base @@ -73,4 +73,4 @@ COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh ENTRYPOINT ["entrypoint.sh"] -CMD php -S 0.0.0.0:80 -t $DOCUMENT_ROOT +CMD ["php", "-S", "0.0.0.0:80", "-t", $DOCUMENT_ROOT]