Alpine images are frequently used with Docker because they provide a very small final Docker image size. This has an advantage when pulling base images from Docker registry, and when pushing them to the registry or production.
Alpine Linux provides
apk tool for managing packages.
Alpine already offers a very good PHP packages in their official repository.
In Docker, you can install the PHP very easily with
FROM alpine:3.7 RUN apk add --no-cache php7
Keep in mind that there is a separate repository for each PHP extension. For example,
if you’ll need
session extension, you’ll need to add the
FROM alpine:3.7 RUN apk add --no-cache php7 php7-session
PHP.earth Docker images provide a custom Alpine repository located at https://repos.php.earth to provide the latest PHP versions and most customizations required for the elegant PHP development with Docker.
The PHP.earth Alpine repository can be used in the following way:
Add the PHP.earth repository to your Dockerfile:
FROM alpine:3.7 ADD https://repos.php.earth/alpine/phpearth.rsa.pub /etc/apk/keys/phpearth.rsa.pub RUN echo "https://repos.php.earth/alpine/v3.7" >> /etc/apk/repositories \ && apk add --no-cache php7.2
Going line by line:
wget -O /etc/apk/keys/phpearth.rsa.pub https://repos.php.earth/alpine/phpearth.rsa.pub
echo "https://repos.php.earth/alpine/v3.7" >> /etc/apk/repositories
apk add --no-cache php7.2
PHP.earth Alpine Linux repository includes the following packages:
PHP packages in PHP.earth repository are prefixed with
apk search --no-cache php7.2
For more information about what is included in the PHP.earth Alpine repository, visit repos.php.earth.