Alpine Linux

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 PHP packages

Alpine already offers a very good PHP packages in their official repository.

In Docker, you can install the PHP very easily with apk:

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 php7-session package:

FROM alpine:3.7

RUN apk add --no-cache php7 php7-session Alpine repository Docker images provide a custom Alpine repository located at to provide the latest PHP versions and most customizations required for the elegant PHP development with Docker.

The Alpine repository can be used in the following way:

Add the repository to your Dockerfile:

FROM alpine:3.7

ADD /etc/apk/keys/
RUN echo "" >> /etc/apk/repositories \
    && apk add --no-cache php7.2

Going line by line:

  1. First line made the 3rd party repository trusted, and is similar to this:
  wget -O /etc/apk/keys/
  1. Then you can register the repository on APK, by adding a new line with repository link in /etc/apk/repositories:
  echo "" >> /etc/apk/repositories
  1. To install PHP:
  apk add --no-cache php7.2 packages Alpine Linux repository includes the following packages:

  • PHP 7.2
  • PHP 7.1
  • PHP 7.0
  • OpenLiteSpeed
  • Composer
  • PHPUnit
  • Some most commonly used PECL extensions

PHP packages in repository are prefixed with php7.2, php7.1, and php7.0.

apk search --no-cache php7.2

For more information about what is included in the Alpine repository, visit