[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

Try out various PHP execution environments! 2016 will be decided by Docker coordination!

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.

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 image on the docker hub is pretty good, and it's not a problem to use it 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.

It is often possible to make changes to an existing docker image and rebuild it, but it is also possible to install modules when compiling PHP. Dockerfile is the procedure manual for building docker, and if you look at it, you can see at a glance what it is doing.

In other words, the docker image you are currently using has a Dockerfile somewhere, and if you make some minor modifications to that Dockerfile and build it, you can get the best 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 lined up on the docker hub, it's easy to find a docker image that is close 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, you will see a link to the Dockerfile managed on github.

Following the link (7.0/apache/Dockerfile) I saw a Dockerfile for creating a docker image for PHP7.0 series + apache.
I'll use this as a slapstick. In your VM, git clone this repository and try making a correction.

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 ./configure option.

Also create a PHP file for testing and COPY it into a docker image.

vi Dockerfile # Dockerfile Near line 59 && ./configure --enable-mbstring # ← Addendum --with-config-file-path="$PHP_INI_DIR" # Added the following COPY instruction to an appropriate location in the Dockerfile # I added 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.

There's no need to do it yourself from scratch, but I think you'll be able to quickly bring it to build by looking for a relatively plain Dockerfile and using it as a slapstick. The official php docker image does not include Vim, so if you want to modify the configuration inside, you should install Vim with apt-get, so there's no problem.

When you create a virtual environment using vagrant, you're inevitably concerned about the file size, but when creating a docker image, it fits 1/4 of the size (of course, it's only the PHP execution environment). In the first place, if you share only the Dockerfile and the files you want to put in the docker image, it is easy to manage them in the git repository.

Being able to turn the entire compilation process into commands is a huge advantage in building an environment at the beginning of development, so we would like to be able to provide the most optimal execution environment without relying on apt-get or yum.

That's it.

If you found this article helpful , please give it a like!
0
Loading...
0 votes, average: 0.00 / 10
549
X facebook Hatena Bookmark pocket
[Webinar] Introduction to Multi-Cloud: Which cloud is best for your business? Get the latest information on the 8 major clouds!

[Webinar] Introduction to Multi-Cloud: Which cloud is best for your business? Get the latest information on the 8 major clouds!

[Webinar] From the operational structure to specific steps! A complete overview of cloud server operation and maintenance

[Webinar] From the operational structure to specific steps! A complete overview of cloud server operation and maintenance

The person who wrote this article

About the author

Yoichi Bandai

My main job is developing web APIs for social games, but I'm also fortunate to be able to do a lot of other work, including marketing.
Furthermore, my portrait rights in Beyond are treated as CC0 by him.