phpearth / docker-php

🐳 Docker For PHP developers - Docker images with PHP, Nginx, OpenLiteSpeed, Apache, Lighttpd, and Alpine
https://docs.php.earth/docker
MIT License
262 stars 79 forks source link
alpine apache docker docker-php nginx openlitespeed php

Docker for PHP developers

Build Status Docker Automated build MIT License

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

PHP.earth

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.4.0alpha1@Alpine 3.9.4 7.4 Small PHP CLI
7.4-cli PHP CLI
7.4-lighttpd Lighttpd 1.4.52
7.4-litespeed OpenLiteSpeed 1.5.0 RC3
7.4-nginx Nginx 1.14.2, FPM
7.4-apache Apache 2.4.39
7.4-cgi PHP CGI
PHP 7.3.4@Alpine 3.9.3 latest, 7.3 Small PHP CLI
7.3-cli PHP CLI
7.3-lighttpd Lighttpd 1.4.52
7.3-litespeed OpenLiteSpeed 1.5.0 RC3
7.3-nginx Nginx 1.14.2, FPM
7.3-apache Apache 2.4.38
7.3-cgi PHP CGI
PHP 7.2.17@Alpine 3.9.3 7.2 Small PHP CLI
7.2-cli PHP CLI
7.2-lighttpd Lighttpd 1.4.52
7.2-litespeed OpenLiteSpeed 1.5.0 RC3
7.2-nginx Nginx 1.14.2, FPM
7.2-apache Apache 2.4.38
7.2-cgi PHP CGI
PHP 7.1.28@Alpine 3.9.3 7.1 Small PHP CLI
7.1-cli PHP CLI
7.1-lighttpd Lighttpd 1.4.52
7.1-litespeed OpenLiteSpeed 1.5.0 RC3
7.1-nginx Nginx 1.14.2, FPM
7.1-apache Apache 2.4.38
7.1-cgi PHP CGI
PHP 7.0.33@Alpine 3.7.3 7.0 Small PHP CLI
7.0-cli PHP CLI
7.0-lighttpd Lighttpd 1.4.48
7.0-litespeed OpenLiteSpeed 1.5.0 RC3
7.0-nginx Nginx 1.12.2, FPM
7.0-apache Apache 2.4.38
7.0-cgi PHP CGI

Tags follow PHP release cycle and PHP supported versions timeline.

PHP Active Support Until Security Support Until Info
7.4 TBD TBD Development 7.4 branch for testing
7.3 TBD TBD Current recommended branch for production
7.2 2019-11-30 2020-11-20 Previous stable branch
7.1 2018-12-01 2019-12-01 Previous branch for legacy projects
7.0 2017-12-03 2018-12-03 Previous branch for legacy projects, not supported anymore

Quick usage

Nginx

Dockerfile for running Nginx HTTP server with PHP FPM:

FROM phpearth/php:7.3-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.3-nginx

RUN apk add --no-cache composer

PHPUnit

To install PHPUnit:

FROM phpearth/php:7.3-nginx

RUN apk add --no-cache phpunit

OpenLiteSpeed

To run OpenLiteSpeed web server:

FROM phpearth/php:7.3-litespeed

Lighttpd

To run Lighttpd web server:

FROM phpearth/php:7.3-lighttpd

PHP extensions

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

FROM phpearth/php:7.3-nginx

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

or install them with pecl:

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

PHP ini settings

To configure extra php.ini: settings, create application specific php.ini and copy the file into docker image:

# php.ini
memory_limit = 512M
FROM phpearth/php:7.3-nginx

COPY php.ini $PHP_INI_DIR/conf.d/my-app.ini

Missing extension?

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

Docker Stack

Docker Stack is way of orchestration of Docker services and simplifies running multiple services of your application. In this example we'll run an Nginx web server with PHP 7.3 FPM with docker-compose.yml file. In a new project directory create a Dockerfile:

FROM phpearth/php:7.3-nginx

The docker-compose.yml file:

version: '3.3'

services:
  app:
    image: my-dev-image
    volumes:
      - .:/var/www/html
    ports:
      - mode: host
        target: 80
        published: 80

The index.php file:

<?php

phpinfo();

Finally we run:

# Initialize a new Swarm for development
docker swarm init
# Build above image
docker build -t my-dev-image -f Dockerfile .
# Deploy the above stack up and running
docker stack deploy -c docker-compose.yaml mystack

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, 7.1, PHP 7.2

To use older versions PHP 7.0, 7.1, or 7.2 use Docker images with 7.0, 7.1, or 7.2:

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.8

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.3

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

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:

Labels

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

License and contributing

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