Public | Automated Build

Last pushed: 12 days ago
Short Description
Docker For PHP Developers - Customized Docker images with PHP, Nginx and OpenLiteSpeed.
Full Description

Docker for PHP developers

Carefully crafted Docker images for PHP developers with PHP 7.0, PHP 7.1, PHP 7.2, Nginx, OpenLiteSpeed, and Apache HTTP Server.

  • Fast and simple PHP extensions installation
  • Optional Composer installation
  • Optional PHPUnit installation
  • runit for running multiple services without overhead
  • Alpine base image with PHP.earth PHP repositories
  • Optimized Docker image sizes
  • Multiple PHP versions

Documentation

Documentation with Docker and PHP recipes is available on PHP.earth.

Docker tags

The following list contains all current Docker tags and what is included in each.

System Docker Tag Features Size
PHP 7.2.0RC6@Alpine 3.6 latest, 7.2 Small PHP CLI
7.2-cli PHP CLI
7.2-litespeed OpenLiteSpeed 1.4.27
7.2-nginx Nginx 1.12.2, FPM
7.2-apache Apache 2.4.27
7.2-cgi PHP CGI
PHP 7.1.11@Alpine 3.6 7.1 Small PHP CLI
7.1-cli PHP CLI
7.1-litespeed OpenLiteSpeed 1.4.27
7.1-nginx Nginx 1.12.2, FPM
7.1-apache Apache 2.4.27
7.1-cgi PHP CGI
PHP 7.0.25@Alpine 3.6 7.0 Small PHP CLI
7.0-cli PHP CLI
7.0-litespeed OpenLiteSpeed 1.4.27
7.0-nginx Nginx 1.12.2, FPM
7.0-apache Apache 2.4.27
7.0-cgi PHP CGI

Tags follow PHP release cycle and PHP supported versions timeline.

PHP Active Support Until Security Support Until Info
7.2 TBD TBD Next PHP version, unstable
7.1 2018-12-01 2019-12-01 Current recommended branch for production
7.0 2017-12-03 2018-12-03 Previous branch for legacy projects

Quick usage

Nginx

Dockerfile for running Nginx HTTP server with PHP FPM:

FROM phpearth/php:7.1-nginx

Build Docker image and run Docker container:

docker build -t custom-php .
docker run --name custom-php-container -p 80:80 -d custom-php

PHP CLI

To run a CLI PHP script:

docker run -it --rm -v `pwd`:/usr/src/myapp -w /usr/src/myapp phpearth/php php script.php

Composer

To install Composer:

FROM phpearth/php:7.1-nginx

RUN apk add --no-cache composer

PHPUnit

To install PHPUnit:

FROM phpearth/php:7.1-nginx

RUN apk add --no-cache phpunit

OpenLiteSpeed

To run OpenLiteSpeed web server:

FROM phpearth/php:7.1-litespeed

PHP extensions

To install additional PHP extensions, you can use packages from the PHP.earth Alpine repository:

FROM phpearth/php:7.1-nginx

RUN apk add --no-cache php7.1-sodium php7.1-intl php7.1-pdo_mysql

or install them with pecl:

apk add --no-cache php7.1-dev gcc g++
pecl install {extension-name}

Missing extension?

In case you'd need an additional extension in the PHP.earth repository, open an issue.

Docker Compose

Docker Compose simplifies usage of multiple containers of your application. In this example we'll run an Nginx web server with PHP 7.1 FPM with docker-compose.yml file. In a new project directory create a Dockerfile:

FROM phpearth/php:7.1-nginx

The docker-compose.yml file:

version: '3.3'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - .:/var/www/html
    ports:
      - 80:80

The index.php file:

<?php

phpinfo();

Finally we run:

docker-compose up

And there should be phpinfo() output visible on http://localhost. Make sure there isn't any other service listening on port 80 before running above command.

PHP 7.0 and PHP 7.2

To use PHP 7.0 or 7.2 use Docker images with 7.2 or 7.0:

FROM phpearth/php:7.2-nginx

RUN apk add --no-cache composer

PHP.earth Alpine repository

These Docker images include the latest PHP versions and packages for Alpine Linux via the 3rd party PHP.earth Alpine repository.

FROM alpine:3.6

ADD https://repos.php.earth/alpine/phpearth.rsa.pub /etc/apk/keys/phpearth.rsa.pub
RUN echo "https://repos.php.earth/alpine" >> /etc/apk/repositories \
    && apk add --no-cache php7.1

PHP.earth Alpine packages are prefixed with php7.0, php7.1 and php7.2.

Building Images

Images are automatically build on Docker Hub.

Docker Cloud and therefore Docker Hub also provides
overriding and customization
of various commands when building images automatically.

There are some hooks defined in the docker/hooks folder:

  • hooks/build - executed when building image
  • hooks/post_push - executed after building image, used to push additional tags
    to Docker Hub.

Labels

Labels are
neat way to expose additional metadata about particular Docker object. We use
Label Schema when defining image labels:

  • build-date - Date and time of the build. Defined as
    org.label-schema.build-date=$BUILD_DATE, where $BUILD_DATE is set dynamically
    via above hooks/build script
  • vcs-url - Repository location on GitHub. Defined as
    org.label-schema.vcs-url="https://github.com/php-earth/docker-php.git"
  • vcs-ref - Reference to commit in Git repository
  • schema-version - Version of the Label Schema in use.
  • vendor - Vendor name of the image creators.
  • name
  • description
  • url

License and contributing

Contributions are most welcome. This repository is released under the MIT license.

Docker Pull Command
Owner
phpearth
Source Repository