docker构建php+nginx+mysql:二、安装php

一、docker search php

[root@iz2ze62mggaeloz5x6ucurz ~]# docker search php
NAME                                                      DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
php                                                       While designed for web development, the PHP …   4428                [OK]                
phpmyadmin/phpmyadmin                                     A web interface for MySQL and MariaDB.          747                                     [OK]
richarvey/nginx-php-fpm                                   Container running Nginx + PHP-FPM capable of…   702                                     [OK]
adminer                                                   Database management in a single PHP file.       235                 [OK]                
php-zendserver                                            Zend Server - the integrated PHP application…   164                 [OK]                
webdevops/php-nginx                                       Nginx with PHP-FPM                              124                                     [OK]
webdevops/php-apache-dev                                  PHP with Apache for Development (eg. with xd…   100                                     [OK]
webdevops/php-apache                                      Apache with PHP-FPM (based on webdevops/php)    84                                      [OK]
phpunit/phpunit                                           PHPUnit is a programmer-oriented testing fra…   70                                      [OK]
bitnami/php-fpm                                           Bitnami PHP-FPM Docker Image                    64                                      [OK]
nazarpc/phpmyadmin                                        phpMyAdmin as Docker container, based on off…   60                                      [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5      ubuntu-16-nginx-php-phpmyadmin-mysql-5          50                                      [OK]
tetraweb/php                                              PHP 5.5, 5.6, 7.0, 7.1 for CI and running te…   32                                      [OK]
wodby/drupal-php                                          PHP for Drupal                                  28                                      [OK]
circleci/php                                              CircleCI images for PHP                         21                                      
clinta/phpipam                                            phpIPAM web IP address management applicatio…   20                                      [OK]
phpdockerio/php7-fpm                                      PHP 7 FPM base container for PHPDocker.io.      14                                      [OK]
graze/php-alpine                                          Smallish php7 alpine image with some common …   11                                      [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mariadb-10   ubuntu-16-nginx-php-phpmyadmin-mariadb-10       11                                      [OK]
phpdockerio/php72-fpm                                     PHP 7.2 FPM base container for PHPDocker.io.    10                                      [OK]
appsvc/php                                                Azure App Service php dockerfiles               8                                       [OK]
phpdockerio/php71-fpm                                     PHP 7.1 FPM base container for PHPDocker.io.    6                                       [OK]
lephare/php                                               PHP container                                   4                                       [OK]
phpdockerio/php71-cli                                     PHP 7.1 CLI base container for PHPDocker.io.    1                                       [OK]

二、docker pull的php镜像

[root@iz2ze62mggaeloz5x6ucurz php-fpm]# docker pull php:7.1-fpm
7.1-fpm: Pulling from library/php
27833a3ba0a5: Already exists 
2d79f6773a3c: Pull complete 
f5dd9a448b82: Pull complete 
95719e57e42b: Pull complete 
736c636e93f8: Pull complete 
b33298c39083: Pull complete 
a7b957d431ad: Pull complete 
5035c53bd080: Pull complete 
756de9316daa: Pull complete 
Digest: sha256:1f5142048e3d6236118006b32cceb0afa635cdcd73360703ba3ec29485d31f80
Status: Downloaded newer image for php:7.1-fpm

三、docker run php

[root@iz2ze62mggaeloz5x6ucurz php-fpm]# docker run -p 9000:9000 --name php -v /data/nginx/html:/usr/share/nginx/html -v /data/php/php-fpm/log:/phplogs -d php:7.1-fpm
b0c3302019134bd94d1b28c431f69bb736cfe69722fbd7a7bc1095792645c131
[root@iz2ze62mggaeloz5x6ucurz php-fpm]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
b0c330201913        php:7.1-fpm         "docker-php-entrypoi…"   6 seconds ago       Up 4 seconds        0.0.0.0:9000->9000/tcp   php
e7d63ec031e2        nginx:latest        "nginx -g 'daemon of…"   19 hours ago        Up 18 hours         0.0.0.0:80->80/tcp       nginx

四、fast_cgi映射docker容器的IP地址

#   查找docker内部容器的ip地址: docker inspect 容器ID或容器名 |grep '"IPAddress"'
[root@iz2ze62mggaeloz5x6ucurz html]# docker inspect --format='{{.NetworkSettings.IPAddress}}' php
172.18.0.3
[root@iz2ze62mggaeloz5x6ucurz html]# vim /data/nginx/conf.d/default.conf
#  站点目录root配置一定是要对应容器内的目录  
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
       # root   /usr/nginx/html;
        index  index.html index.htm index.php;
        autoindex  on;
   # try_files $uri /index/index/page.html;
        #try_files $uri /index/map/page.html;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #以下为修改的地方
    location ~ \.php$ {
        root          /usr/share/nginx/html;
        #fastcgi_pass   127.0.0.1:9000;
        #这里为映射
        fastcgi_pass  172.18.0.3:9000;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #这里如果没修改会出现 file not fond
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
#以上为修改的地方
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}

五、 重启

[root@iz2ze62mggaeloz5x6ucurz html]# docker  restart  nginx
nginx

六、测试是否成功,创建index.php

docker构建php+nginx+mysql:二、安装php_第1张图片

你可能感兴趣的:(PHP)