How to: Own PHP image

I read yesterday a discussion on phpc.social a Mastodon instance for the PHP community about docker images and how to make them work for you. Btw, all the following hard work is done by my great colleague Thomas Spigel.

In our case, we want to use it for deployments, testing (especially cypress) and our newest addition serverless to deploy bref.

Extend the Dockerfile

We have a small little repository with our own Dockerfile and a README.md. The Dockerfile looks like this:

FROM php:8.2-cli
MAINTAINER Developer dev@example.org

RUN apt-get update && \
    apt-get install -y --no-install-recommends\
	unzip \
	libsodium-dev \
	libssh2-1-dev \
	git \
	zlib1g-dev \
	libpng-dev \
	libcurl4-openssl-dev \
	libxml2-dev \
	libonig-dev \
	libzip-dev \
	ssh \
	wget \
	rsync \
	gpg \
    jq \
    xvfb \
    libgconf-2-4 \
    libatk1.0-0 \
    libatk-bridge2.0-0 \
    libgdk-pixbuf2.0-0 \
    libgtk-3-0 \
    libgbm-dev \
    libnss3-dev \
    libxss-dev \
    libasound-dev \
    libasound2-dev \
    libasound2 \
    dirmngr \
    gpg-agent

    # Install serverless
RUN curl -o- -L https://slss.io/install | VERSION=3.38.0 bash

    # Install phive
RUN wget -O phive.phar https://phar.io/releases/phive.phar  && \
    wget -O phive.phar.asc https://phar.io/releases/phive.phar.asc  && \
    gpg --keyserver hkps://keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79  && \
    gpg --verify phive.phar.asc phive.phar  && \
    chmod +x phive.phar  && \
    mv phive.phar /usr/local/bin/phive

    # cypress reqs
RUN wget https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions -O /usr/local/bin/install-php-extensions && \
    wget https://getcomposer.org/download/latest-stable/composer.phar -O /usr/local/bin/composer && chmod +x /usr/local/bin/composer && \
    chmod +x /usr/local/bin/install-php-extensions  && \
    IPE_GD_WITHOUTAVIF=1 install-php-extensions gd intl pdo_mysql zip pcntl  && \
    git clone https://github.com/php/pecl-networking-ssh2.git /usr/src/php/ext/ssh2 && \
    IPE_GD_WITHOUTAVIF=1 docker-php-ext-install -j$(nproc) gd intl pdo_mysql zip ssh2 pcntl && \
    rm -rf /var/lib/apt/lists/*

README.md

And then we have a readme file which contains the command to build the images (even a linux compatible images built on mac) and upload it to docker.

docker buildx build . --platform linux/amd64 --push -t developer/name:8.2

4 thoughts on “How to: Own PHP image

  1. This image will propably be bigger than required, since you did not delete the apt-get cache after installing required packages. These caches can easily save up to hundreds of MB

Leave a Reply