Docker's method of building php ES2en ES3en images from zero

  • 2020-12-19 21:17:29
  • OfStack

Although I've run a few projects with docker before, The mirroring part is not well understood, and since the off-the-shelf images on the web contain too many unused libraries, I decided to build one of my own images from scratch.

alpine linux is the base mirror


docker pull gliderlabs/alpine

alpine linux mirror address

The latest VERSION of tag is version 3.8 and the mirror is only the size of 4M, which is very compact.

Run the mirror


docker run -it gliderlabs/alpine

After running, you can see that there is a basic linux file system inside. There is no demonstration here, but those who are interested can try it.

Install php and nginx


apk update
apk add php7 nginx

Next, you can go ahead and install the php-related extension pack or any other linux extension pack, depending on your needs.

Search for extension packages, such as the php7 toolkit, through the following instructions:


# apk search php7

Install the php extension

apk add php7-mysqli php7-pdo_mysql php7-mbstring php7-json php7-zlib php7-gd php7-intl php7-session php7-fpm php7-memcached

The directory structure

php7 directory: /etc/php7 nginx directory: /etc/nginx

Start ES55en-ES56en and nginx


#  First create pid File, otherwise nginx Don't run 
mkdir /run/nginx 
touch /run/nginx/nginxpid

#  First run php And then run nginx
/usr/sbin/php-fpm7
/usr/sbin/nginx

At this point, you can see that php and nginx are up and running, and the mirror environment is almost complete. Next, you can see how to save the image.

Create a mirror image

Start another terminal and use docker ps to view the image ID. The following instructions can save the image:


docker commit -a "yisonli" -m "my first php7-nginx" 9d9c6030e5e9 yisonli/php7-nginx-alpine:0.1

Note: mirror ID, 9 d9c6030e5e9 yisonli/php7 - nginx - alpine to preserve image name, version is defined as 0.1

Run the newly generated image

Bind port 8080 to see what happens


docker run -it -p 8080:8080 yisonli/php7-nginx-alpine:0.1

After manually launching php-ES93en and nginx, the browser will see the effect.

http://127.0.0.1:8080/index.php

Additional records of docker

[Shared folder]


docker run -v `pwd`/www:/var/www/html -it -p 8080:8080 yisonli/php7-nginx-alpine:0.1

[Delete containers that are not running]


docker rm $(docker ps -a -q)

[Build mirror image in Dockerfile]


docker build -t yisonli/php7-nginx-alpine:0.2 .

0.2 is the process of this article after a little optimization, written Dockerfile build out, and with startup script.

Uploaded to Docker Hub and available for download.

[Add extra tag tags to the image]


docker run -it gliderlabs/alpine
0

Related articles: