Update PHP canonical examples from 5.6 to 7.0

This commit is contained in:
Tianon Gravi 2016-07-14 14:31:27 -07:00
parent 5785068d91
commit 1f0177487b
1 changed files with 9 additions and 9 deletions

View File

@ -15,7 +15,7 @@ For PHP projects run through the command line interface (CLI), you can do the fo
### Create a `Dockerfile` in your PHP project ### Create a `Dockerfile` in your PHP project
```dockerfile ```dockerfile
FROM php:5.6-cli FROM php:7.0-cli
COPY . /usr/src/myapp COPY . /usr/src/myapp
WORKDIR /usr/src/myapp WORKDIR /usr/src/myapp
CMD [ "php", "./your-script.php" ] CMD [ "php", "./your-script.php" ]
@ -33,7 +33,7 @@ $ docker run -it --rm --name my-running-app my-php-app
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: 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:
```console ```console
$ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:5.6-cli php your-script.php $ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.0-cli php your-script.php
``` ```
## With Apache ## With Apache
@ -43,7 +43,7 @@ More commonly, you will probably want to run PHP in conjunction with Apache http
### Create a `Dockerfile` in your PHP project ### Create a `Dockerfile` in your PHP project
```dockerfile ```dockerfile
FROM php:5.6-apache FROM php:7.0-apache
COPY src/ /var/www/html/ COPY src/ /var/www/html/
``` ```
@ -57,7 +57,7 @@ $ docker run -d --name my-running-app my-php-app
We recommend that you add a custom `php.ini` configuration. `COPY` it into `/usr/local/etc/php` by adding one more line to the Dockerfile above and running the same commands to build and run: We recommend that you add a custom `php.ini` configuration. `COPY` it into `/usr/local/etc/php` by adding one more line to the Dockerfile above and running the same commands to build and run:
```dockerfile ```dockerfile
FROM php:5.6-apache FROM php:7.0-apache
COPY config/php.ini /usr/local/etc/php/ COPY config/php.ini /usr/local/etc/php/
COPY src/ /var/www/html/ COPY src/ /var/www/html/
``` ```
@ -71,7 +71,7 @@ We provide the helper scripts `docker-php-ext-configure`, `docker-php-ext-instal
In order to keep the images smaller, PHP's source is kept in a compressed tar file. To facilitate linking of PHP's source with any extension, we also provide the helper script `docker-php-source` to easily extract the tar or delete the extracted source. Note: if you do use `docker-php-source` to extract the source, be sure to delete it in the same layer of the docker image. In order to keep the images smaller, PHP's source is kept in a compressed tar file. To facilitate linking of PHP's source with any extension, we also provide the helper script `docker-php-source` to easily extract the tar or delete the extracted source. Note: if you do use `docker-php-source` to extract the source, be sure to delete it in the same layer of the docker image.
```Dockerfile ```Dockerfile
FROM php:5.6-apache FROM php:7.0-apache
RUN docker-php-source extract \ RUN docker-php-source extract \
# do important things \ # do important things \
&& docker-php-source delete && docker-php-source delete
@ -82,7 +82,7 @@ RUN docker-php-source extract \
For example, if you want to have a PHP-FPM image with `iconv`, `mcrypt` and `gd` extensions, you can inherit the base image that you like, and write your own `Dockerfile` like this: For example, if you want to have a PHP-FPM image with `iconv`, `mcrypt` and `gd` extensions, you can inherit the base image that you like, and write your own `Dockerfile` like this:
```dockerfile ```dockerfile
FROM php:5.6-fpm FROM php:7.0-fpm
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
libfreetype6-dev \ libfreetype6-dev \
libjpeg62-turbo-dev \ libjpeg62-turbo-dev \
@ -100,7 +100,7 @@ Remember, you must install dependencies for your extensions manually. If an exte
Some extensions are not provided with the PHP source, but are instead available through [PECL](https://pecl.php.net/). To install a PECL extension, use `pecl install` to download and compile it, then use `docker-php-ext-enable` to enable it: Some extensions are not provided with the PHP source, but are instead available through [PECL](https://pecl.php.net/). To install a PECL extension, use `pecl install` to download and compile it, then use `docker-php-ext-enable` to enable it:
```dockerfile ```dockerfile
FROM php:5.6-fpm FROM php:7.0-fpm
RUN apt-get update && apt-get install -y libmemcached-dev \ RUN apt-get update && apt-get install -y libmemcached-dev \
&& pecl install memcached \ && pecl install memcached \
&& docker-php-ext-enable memcached && docker-php-ext-enable memcached
@ -111,7 +111,7 @@ RUN apt-get update && apt-get install -y libmemcached-dev \
Some extensions are not provided via either Core or PECL; these can be installed too, although the process is less automated: Some extensions are not provided via either Core or PECL; these can be installed too, although the process is less automated:
```dockerfile ```dockerfile
FROM php:5.6-apache FROM php:7.0-apache
RUN curl -fsSL 'https://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz' -o xcache.tar.gz \ RUN curl -fsSL 'https://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz' -o xcache.tar.gz \
&& mkdir -p xcache \ && mkdir -p xcache \
&& tar -xf xcache.tar.gz -C xcache --strip-components=1 \ && tar -xf xcache.tar.gz -C xcache --strip-components=1 \
@ -132,5 +132,5 @@ RUN curl -fsSL 'https://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.
If you don't want to include a `Dockerfile` in your project, it is sufficient to do the following: If you don't want to include a `Dockerfile` in your project, it is sufficient to do the following:
```console ```console
$ docker run -d -p 80:80 --name my-apache-php-app -v "$PWD":/var/www/html php:5.6-apache $ docker run -d -p 80:80 --name my-apache-php-app -v "$PWD":/var/www/html php:7.0-apache
``` ```