Skip to content

Wordpress-Image: choice of WP version with multistage build #206

@designzwang

Description

@designzwang

Hi,

I like having a combined Apache-FPM image for wordpress, so I want to use your very useful pre-build wordpress image(s) .

However we need to be able to not only chose the PHP version, but also use different WP versions, and we need to enable additional modules for php and install some additional tools.

My plan is to use a multistage build with the original Wordpress images as a source and copy the WP files from the official image into /var/www/html of your FPM image.

That way, we will have an image that already has the desired php and wordpress version , and then we have the choice, depending on the project, to either use the provided version of the image or mount a project specific tree into /var/www/html.

On first sight it works fine - or do you see any problems when we do this?
The dockerfile is attached below.
Regards,
Uli

# Dockerfile for adding a specific WP version into shinsenter FPM WP image
# in this example, values are hardcoded - actually they will be set by Jenkins at build time
ARG KDEPHP=8.1
ARG KDEWP=6.8

# we need both wordpress (for official wordpress files in specific versions) and fpm Image from shinsenter  :
ARG WP_FPM_IMAGE=our-repo.example.com/dockerhub-proxy/shinsenter/wordpress:php${KDEPHP}
ARG WP_OFFICIAL_IMAGE=our-repo.example.com/dockerhub-proxy/library/wordpress:${KDEWP}-php${KDEPHP}-apache

# alias for copying matching WP files from offical image
FROM ${WP_OFFICIAL_IMAGE} AS wordpress_files
ENV KDEPHP=$KDEPHP
ENV KDEWP=$KDEWP

# clean out plugins and themes to make space for our own collection
RUN rm -r /usr/src/wordpress/wp-content/plugins/* \
    && rm -r /usr/src/wordpress/wp-content/themes/* \
    && ( cp /usr/src/wordpress/wp-config-docker.php /usr/src/wordpress/wp-config-docker-dist.php || true ) \
    && touch /usr/src/wordpress/transferred-from-wp-original-src-by-ncs-Dockerfile-build

# shinsenter fpm is our real base image
FROM ${WP_FPM_IMAGE}
ENV KDEPHP=$KDEPHP
ENV KDEWP=$KDEWP

COPY --from=wordpress_files /usr/src/wordpress /var/www/html

# install or enable other tools needed. Not all apache modules are enabled by default, better do that
RUN apt-get update && \
 phpaddmod imagick bz2 && \
 apt-get update && apt-get install -y git curl mariadb-client ssmtp libz-dev less vim sudo gettext &&  \
 rm -rf /var/lib/apt/lists/* && \
  apt-get clean && \
 a2enmod access_compat alias auth_basic authn_core authn_file authz_core authz_host authz_user deflate dir env expires filter mime negotiation remoteip reqtimeout rewrite setenvif status && \
 sed -i 's/# RemoteIPTrustedProxy/RemoteIPInternalProxy /ig' /etc/apache2/apache2.conf

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions