The whole process of building php7 and nginx running environment with docker

Since we used to use docker image to enter the container and use yum to install nginx or php, we found that the whole image is larger and faster by 2G. Large documents will affect the environmental shift value, and there is no technical content. Today, I found a sub environment installation on the Internet to separate nginx and php into two images. Here is the process of my installation Environment introduction:

  • Host root directory / home/docker
  • Host website root directory / home/docker/www
  • Related directories of host nginx / home/docker/nginx/conf.d

Preparation 1. Using docker accelerator

curl -sSL | sh -s http://68abbefd.m.daocloud.ioservice docker restart

2. Download related images

docker pull nginx
docker pull php:7.1.0-fpm

It's a little slow. Wait.

3. Establish related directory

mkdir -p  /home/docker/www
mkdir -p /home/docker/nginx/conf.d

4. Edit default.conf

vim /docker/nginx/conf.d/default.conf # Here is an example
server {  
listen  80 default_server;  
server_name _;
  root   /usr/share/nginx/html; 
  location / {   index index.html index.htm index.php;   
  autoindex off; 
	  location ~ \.php(.*)$ {  
	  root   /var/www/html/;   
	  fastcgi_index index.php;   
	  fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;   
	  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;   
	  fastcgi_param PATH_INFO $fastcgi_path_info;   
	  fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;   
	  include  fastcgi_params; 

###Setting up the environment 1. Start php image

docker run -p 9000:9000 --name myphp \-v  /home/docker/www/:/var/www/html/  --privileged=true  -d php:7.1.0-fpm  #php7.1 enabled

2. Start nginx image

docker run -p 80:80 --name mynginx \-v /docker/www:/usr/share/nginx/html \-v /docker/nginx/conf.d:/etc/nginx/conf.d \--privileged=true \-d nginx  

3. View image health status

docker ps-a

4. Generate PHP test file info.php

At / home/docker/www/info.php

<?php phpinfo();" >

========Attach my debugging history order===========

1,docker run -it -p 8081:80 --name my_nginx -v /home/docker/nginx_conf:/etc/nginx/conf.d -v /home/docker/www:/usr/share/nginx/html --privileged=true   #Running nginx status, you can use - d

2,docker exec -it [my_nginx container ID]   #Enter to view nginx status

3,docker run -p 9000:9000 --name myphp -v /home/docker/www/:/var/www/html/ --privileged=true -d php:7.1.0-fpm    #Run php

 curl http://121.12. *: 8081 successful
 docker inspect --format='{{.NetworkSettings.IPAddress}}' myphp
 vi /home/docker/nginx_conf/default.conf [See the host document for details]

 docker ps


Keywords: Docker Nginx PHP curl

Added by luxe on Fri, 03 Apr 2020 12:00:19 +0300