Merge pull request #638 from infosiftr/php-rm-src
Add explanation to php for `docker-php-source`
This commit is contained in:
commit
9d6926337c
|
|
@ -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,11 +43,11 @@ 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/
|
||||||
```
|
```
|
||||||
|
|
||||||
Where `src/` is the directory containing all your php code. Then, run the commands to build and run the Docker image:
|
Where `src/` is the directory containing all your PHP code. Then, run the commands to build and run the Docker image:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ docker build -t my-php-app .
|
$ docker build -t my-php-app .
|
||||||
|
|
@ -57,23 +57,32 @@ $ 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/
|
||||||
```
|
```
|
||||||
|
|
||||||
Where `src/` is the directory containing all your php code and `config/` contains your `php.ini` file.
|
Where `src/` is the directory containing all your PHP code and `config/` contains your `php.ini` file.
|
||||||
|
|
||||||
### How to install more PHP extensions
|
### How to install more PHP extensions
|
||||||
|
|
||||||
We provide the helper scripts `docker-php-ext-configure`, `docker-php-ext-install`, and `docker-php-ext-enable` to more easily install PHP extensions.
|
We provide the helper scripts `docker-php-ext-configure`, `docker-php-ext-install`, and `docker-php-ext-enable` to more easily install PHP extensions.
|
||||||
|
|
||||||
|
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
|
||||||
|
FROM php:7.0-apache
|
||||||
|
RUN docker-php-source extract \
|
||||||
|
# do important things \
|
||||||
|
&& docker-php-source delete
|
||||||
|
```
|
||||||
|
|
||||||
#### PHP Core Extensions
|
#### PHP Core Extensions
|
||||||
|
|
||||||
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-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 \
|
||||||
|
|
@ -84,14 +93,14 @@ RUN apt-get update && apt-get install -y \
|
||||||
&& docker-php-ext-install -j$(nproc) gd
|
&& docker-php-ext-install -j$(nproc) gd
|
||||||
```
|
```
|
||||||
|
|
||||||
Remember, you must install dependencies for your extensions manually. If an extension needs custom `configure` arguments, you can use the `docker-php-ext-configure` script like this example.
|
Remember, you must install dependencies for your extensions manually. If an extension needs custom `configure` arguments, you can use the `docker-php-ext-configure` script like this example. There is no need to run `docker-php-source` manually in this case, since that is handled by the `configure` and `install` scripts.
|
||||||
|
|
||||||
#### PECL extensions
|
#### PECL extensions
|
||||||
|
|
||||||
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-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
|
||||||
|
|
@ -102,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-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 \
|
||||||
|
|
@ -123,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
|
||||||
```
|
```
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue