Try out various PHP execution environments! 2016 will be decided by Docker coordination!
table of contents
Hello.
I'm Mandai, in charge of Wild on the development team.
If you want to create a fancy development environment with docker, why not try creating an original docker image with docker build?
If you have a docker image that is easy to mix and match, you will have a wide range of arrangements!
This is written as part of the docker introductory series.
If you would like to read past Docker introductory series, please follow the links below.
- Very polite! Introduction to docker by copying and pasting
- Very polite! Introduction to docker by copying and pasting ~Dockerfile and docker build edition~
Please note that this is not a series that can be done by copying and pasting, as this cannot be done by copying and pasting. Not bad.
About PHP execution environment
The docker images listed on docker hub are quite excellent and there is no problem in using them as is.
- For example, you might want to be a little more particular about the directory where the source files are placed.
- I want to encode an audio file using ffmpeg from PHP.
- You want to use PHP with lots of extension modules.
I think the only way to meet such demands is to rebuild the docker image on your own.
In many cases, this can be done by making changes to the existing docker image and building it again, but
it is also possible to include the module at the time of compiling PHP.
The Dockerfile is a step-by-step guide for building docker, and if you look at it, you can understand at a glance what is being done.
In other words, the docker image you are currently using has a Dockerfile somewhere, and
if you make a few modifications to that Dockerfile and build it, you can get the optimal docker image you want.
Furthermore, there are many Dockerfiles that have been uploaded to github and are open to the public (the more official Docker images there are, the more likely they are), so you can look at various Dockerfiles and steal the method. Please bring it.
This time, I would like to create a docker image that includes multibyte-compatible PHP, using the official PHP docker image as a reference.
First, find the base docker image
If you look at the docker images listed on docker hub, you can easily find a docker image that is similar to what you want to create.
This time, I would like to make some modifications based on
the official PHP docker image If you look at the page, there is a link to a Dockerfile maintained on github.
When I followed the link (7.0/apache/Dockerfile), I saw a Dockerfile for creating a PHP7.0 series + apache docker image.
I'll use this as a starting point.
Let's git clone this repository on the VM and make some modifications.
cd ~ vagrant@vagrant:~$ git clone https://github.com/docker-library/php.git vagrant@vagrant:~$ cd /home/vagrant/php/7.0/apache
Add "--enable-mbstring" to the options of ./configure.
Also, create a PHP file for testing and copy it to the docker image.
vi Dockerfile # Dockerfile around line 59 && ./configure --enable-mbstring # ← Add --with-config-file-path="$PHP_INI_DIR" # Add the following COPY command to an appropriate place in the Dockerfile # I , added before WORKDIR /var/www/html. COPY mbstring.php /var/www/html/
Try compiling PHP with docker build
Once you have fixed it, create mbstring.php.
echo "<?php echo mb_convert_kana('1234567890', 'N');" > mbstring.php
Once created, try docker build.
vagrant@vagrant:~/php/7.0/apache$ docker build -t myphp7 .
Unlike
the previous this build Once the build is complete, let's create a docker container from the docker image.
vagrant@vagrant:~/php/7.0/apache$ docker run -it myphp7 /bin/bash root@66c8bbc720a9:/var/www/html# ls mbstring.php root@66c8bbc720a9:/var/www/html# service apache2 start [....] Starting web server: apache2AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message . ok root@66c8bbc720a9:/var/ www/html# curl http://localhost/mbstring.php 1234567890root@66c8bbc720a9:/var/www/html#
It looks like it executes an instruction to convert half-width numbers to full-width numbers and then exits, but the conversion is successful without any problems.
You don't have to do it yourself from scratch, I think you can find a relatively plain Dockerfile and use it as a starting point to quickly get to the build stage.
The official PHP docker image does not include vim, so if you want to modify the configuration inside it, you should install vim using apt-get.
When creating a virtual environment using vagrant, I am always concerned about the file size, but
when creating a docker image, it was 1/4 the size, so I would like to share it (of course, only the PHP execution environment) It's also easy.
In the first place, if you only share the Dockerfile and the files to be included in the docker image, it is easy to manage it with a git repository.
Being able to convert the entire compilation process into a command has many benefits when building an environment at the beginning of development, so you
can prepare the optimal execution environment by adding the optimal compilation options without relying too much on apt-get or yum. I want to be like that.
That's it.