loliee / docker-php

My php dev container...

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

docker-php

Build Status

PHP dev image based on official php-image with composer and phpcs. This image also include nodejs, npm, bower, git sometimes used by composer's pre/post install scripts.

Datetime is set by default to Europe/Paris.

How to use this image

Run a single PHP script:

For many simple, single file projects, you may find it inconvenient to write a complete Dockerfile. In such cases, you can run a PHP script by using the PHP Docker image directly:

$ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp loliee/docker-php:5.6 php your-script.php

Define shell functions

Some functions to put in your .zshrc or bashrc.

PHPD=${PHPD:='php:5.6'}

function phpd(){
  if  [[ $1 == /* ]]; then MOUNT=$(dirname "$1"); else MOUNT=$PWD; fi
  eval "$(docker-machine env dev)"
  docker run -ti --rm --name php56-"$USER"-"$(gdate +%s%N)" -v "$MOUNT":"$MOUNT" -w "$MOUNT" "$PHPD" php "$@"
  unset MOUNT
}

function composerd() {
  local args="$*"
  local name="$PHPD-composer-$args"
  if hash gdate &>/dev/null; then
    name="$name"-"$(gdate +%s%N)"
  else
    name="$name"-"$(gdate +%sN)"
  fi
  # shellcheck disable=SC2001
  name="$(echo "$name" | sed "s/[^a-zA-Z0-9_.-]/_/")"
  if  [[ $1 == /* ]]; then mount=$(dirname "$1"); else mount=$PWD; fi
  docker run -ti --rm --name "$name" -v "$mount":"$mount" -w "$mount" loliee/docker-"$PHPD" php -n \
    -dtimezone=Europe/Paris -dextension=bz2.so -dextension=ftp.so -dextension=intl.so \
    -dextension=mysql.so -dextension=redis.so -dextension=soap.so -dextension=tidy.so \
    -dextension=bcmath.so -dextension=pcntl.so -dextension=pgsql.so -dextension=xsl.so -dextension=zip.so \
    -dmemory_limit=-1 /usr/local/bin/composer.phar "$@"
  unset mount name
}

You should be able to run the following command to execute php in an ephemere container:

phpd -v

Tip

Use composer in HTTP mode (more easy to cache with a proxy) and use a auth.json file for private repo.

To add a token in a repo:

composer config github-oauth.github.com your_github_token 

Build image with OCI8

git clone https://github.com/loliee/docker-php.git
cd docker-php/5.6/oci8

Download instantclient-basic-linux.x64-12.1.0.2.0.zip and instantclient-sdk-linux.x64-12.1.0.2.0.zip from oracle website and put zip files in docker-php/5.6/oci8/instantclient directory.

docker build -t loliee/docker-php:5.6-oci8

Extensions

Setup with the following extensions:

  • bcmath
  • bz2
  • ctype
  • curl
  • exif
  • fileinfo
  • ftp
  • gd
  • gettext
  • hash
  • iconv
  • imap
  • intl
  • json
  • mbstring
  • mcrypt
  • mongodb-1.1.2
  • mysql
  • mysqli
  • oci8 (Optional, require custom build)
  • odbc
  • opcache
  • pcntl
  • pdo
  • pdo_mysql
  • pdo_pgsql
  • pdo_sqlite
  • pgsql
  • phar
  • redis
  • simplexml
  • soap
  • sockets
  • sysvmsg
  • sysvsem
  • sysvshm
  • tidy
  • tokenizer
  • xdebug-2.3.3
  • xml
  • xmlreader
  • xmlrpc
  • xmlwriter
  • xslt
  • zip

About

My php dev container...


Languages

Language:Ruby 100.0%