PHP/PHP-FPM/Jenkins Docker image for development/CI, based on Alpine Linux for minimal size
Switch branches/tags
Nothing to show
Clone or download
Latest commit 0d9ffd3 Sep 30, 2018

README.md

Docker Pulls

Docker Build Status Docker Automated build

PHP development Docker image

PHP/PHP-FPM/Jenkins Docker image for development/CI, based on Alpine Linux for minimal size

Bundled with:

Available tags

CLI

latest PHP 7.2 Dockerfile Docker Size
cli PHP 7.2 Dockerfile Docker Size
7 PHP 7.2 Dockerfile Docker Size
7.3 PHP 7.3-rc Dockerfile Docker Size
7.2 PHP 7.2 Dockerfile Docker Size
7.1 PHP 7.1 Dockerfile Docker Size
7.0 PHP 7.0 Dockerfile Docker Size
5 PHP 5.6 Dockerfile Docker Size
5.6 PHP 5.6 Dockerfile Docker Size

FPM

fpm-latest PHP 7.2 Dockerfile Docker Size
fpm PHP 7.2 Dockerfile Docker Size
7-fpm PHP 7.2 Dockerfile Docker Size
7.3-fpm PHP 7.3-rc Dockerfile Docker Size
7.2-fpm PHP 7.2 Dockerfile Docker Size
7.1-fpm PHP 7.1 Dockerfile Docker Size
7.0-fpm PHP 7.0 Dockerfile Docker Size
5-fpm PHP 5.6 Dockerfile Docker Size
5.6-fpm PHP 5.6 Dockerfile Docker Size

Jenkins

jenkins-latest PHP 7.2 Dockerfile Docker Size
jenkins PHP 7.2 Dockerfile Docker Size
7-jenkins PHP 7.2 Dockerfile Docker Size
7.3-jenkins PHP 7.3-rc Dockerfile Docker Size
7.2-jenkins PHP 7.2 Dockerfile Docker Size
7.1-jenkins PHP 7.1 Dockerfile Docker Size
7.0-jenkins PHP 7.0 Dockerfile Docker Size
5-jenkins PHP 5.6 Dockerfile Docker Size
5.6-jenkins PHP 5.6 Dockerfile Docker Size

Jenkins version is specially designed to be run as a Jenkins slave on a CI pipeline

Important support notice!

PHP 5.6 and PHP 7.0 will reach end of life during December 2018, all tags related with this versions of PHP will be removed at the end of January 2019. Start migration to newer versions as soon as possible

Environment variables

USER_UID

  • For FPM and Jenkins versions
  • Type: int
  • Default: not set
  • Recommended

In order to avoid file access problems it is recommended to set this variable to your user's UID. You can find your UID by running id -u

USER_GID

  • For FPM and Jenkins versions
  • Type: int
  • Default: not set
  • Recommended

In order to avoid file access problems it is recommended to set this variable to your user's GID. You can find your GID by running id -g

XDEBUG_DISABLE

  • Type: int
  • Default: 0

Disable Xdebug by setting a non zero value

XDEBUG_REMOTE_HOST

  • Type: string
  • Default: auto discovered host's ip

Remote server (host) IP to connect to

XDEBUG_REMOTE_PORT

  • Type: integer
  • Default: 9000

Remote server port to connect to, IDE should be listening on this port

XDEBUG_REMOTE_AUTOSTART

  • Type: integer
  • Default: 0
  • Not recommended

Auto start remote debugging

XDEBUG_IDE_KEY

  • Type: string
  • Default: not set
  • Not recommended

Fixed remote session identifier

Note: escape the string for use in sed

XDEBUG_FILE_LINK_FORMAT

  • Type: string
  • Default: not set

Protocol format to integrate IDEs with stack trace file links. You can provide your custom format or use one of the supported formats: "phpstorm", "idea", "sublime", "textmate", "emacs" or "macvim"

Note: if you use your custom format remember to escape the string for use in "sed" command

Volumes

/app

The default working directory. You should mount your project root path in this volume.

/var/log/php

Logging volume for PHP and PHP-FPM logs and Xdebug log, profile and trace files.

Usage

Getting the image

docker pull juliangut/phpdev:latest

docker pull juliangut/phpdev:fpm-latest

docker pull juliangut/phpdev:jenkins-latest

Running a container

docker run -it --rm -v `pwd`:/app juliangut/phpdev:latest

docker run -d -e USER_UID=`id -u` -e USER_GID=`id -g` -v `pwd`:/app juliangut/phpdev:fpm-latest

Running built-in server

docker run -d -p 8080:8080 -v `pwd`:/app juliangut/phpdev:latest php -S 0.0.0.0:8080 -t /app/public
With Docker Compose
version: "3"

services:
  app:
    image: juliangut/phpdev:latest
    ports:
      - 8080:8080
    volumes:
      - .:/app
    command: "php -S 0.0.0.0:8080 -t /app/public"

Access running server on "http://localhost:8080"

Running a composer command

In order to run a composer command you should provide docker with your user/group info, otherwise files resulting from composer command won't have your (correct) permissions

docker run --rm -u `id -u`:`id -g` -v `pwd`:/app juliangut/phpdev:latest composer [command]

docker run --rm -u `id -u`:`id -g` -v `pwd`:/app juliangut/phpdev:fpm-latest composer [command]

Accessing a running container

docker exec -it [container_id] /bin/bash

Using Xdebug

It is not recommended to have a fixed remote session identifier and/or an auto-started remote session using "XDEBUG_IDE_KEY" and "XDEBUG_REMOTE_AUTOSTART" environment variables respectively.

The preferred way of starting a remote debug session is by setting remote session identifier dynamically by one of the following means:

  • On browser by setting "XDEBUG_SESSION" cookie with the session identifier as its value
  • On HTTP request (cURL) by adding "XDEBUG_SESSION_START" parameter to the URI or as a POST parameter. eg: curl -X POST -F "XDEBUG_SESSION_START=PHPSTORM" http://example.local
Xdebug profiler

To activate the profiler set "XDEBUG_PROFILE" cookie. Profile cachegrind.out.* files will be saved into /var/log/php directory

Xdebug trace

To activate the trace set "XDEBUG_TRACE" cookie. Trace *.xt files will be saved into /var/log/php directory

Browser support

There are browser plugins/extensions to toggle these debug cookies easily

Debugging with PHPStorm

Review Xdebug configuration

Xdebug configuration

  • Port must be the same previously defined in XDEBUG_REMOTE_PORT environment variable
  • If you're using any of juliangut/pphpdev:fpm* versions remember that port 9000 has already been taken by PHP-FPM, use 9001 or any other you please instead
Create a server

server configuration

  • Server name will be used later so make it stand out
  • Host and port must be the same set in built-in server. You you can use "0.0.0.0" to allow any host
  • Map your project root to container location (/app)
Start listening for Xdebug connections

Click the phone icon to start listening for incoming connections and create a breakpoint

start listening

Start the container

Setting PHP_IDE_CONFIG environment variable to the server name you defined earlier

docker run -d -p 8080:8080 -e PHP_IDE_CONFIG="serverName=Test" -e XDEBUG_FILE_LINK_FORMAT=phpstorm -v `pwd`:/app juliangut/phpdev:latest php -S 0.0.0.0:8080 -t /app/public
Using Docker Compose
version: "3"

services:
  app:
    image: juliangut/phpdev:latest
    ports:
      - 8080:8080
    environment:
      PHP_IDE_CONFIG: serverName=Test
      XDEBUG_FILE_LINK_FORMAT: phpstorm
    volumes:
      - .:/app
    command: "php -S 0.0.0.0:8080 -t /app/public"

Firewalld & NetworkManager notice

By default firewalld blocks all outgoing connections from docker containers, such as Xdebug connection to port 9000 on host. In order to allow docker containers to connect with Xdebug server you need to include docker0 interface into a "trusted" zone both on NetworkManager and firewalld:

Assign docker0 interface to "trusted" zone and stop NetworkManager service

nmcli connection modify docker0 connection.zone trusted
systemctl stop NetworkManager.service

Assign "trusted" zone for docker0 interface on firewalld. Additionally 172.0.0.0/8 source is added to cover any created docker network

firewall-cmd --permanent --zone=trusted --change-interface=docker0
firewall-cmd --permanent --zone=trusted --add-source=172.0.0.0/8
firewall-cmd --reload

Restart NetworkManager and reassign docker0 interface just in case

systemctl start NetworkManager.service
nmcli connection modify docker0 connection.zone trusted

Restart docker service so it recreates its iptables

systemctl restart docker.service

Extending the image

The image comes with just the minimum PHP extensions, you most probably will need more.

FROM juliangut/phpdev:latest

RUN docker-php-ext-install \
    pdo_mysql \
  && pecl install \
    mongodb \
    redis \
  && docker-php-ext-enable \
    mongodb \
    redis \
  \
  && composer global require phpunit/phpunit

License

See file LICENSE included with the source code for a copy of the license terms.