构建nginx,php的docker镜像-手动配置

php-fpm

开启一个测试的容器

docker run -di -p 9005:9000 --name php-fpm-test php:5.6.13-fpm

对容器进行自定义

登录进容器

docker exec -it php-fpm-test /bin/bash

查看配置文件位置(用于获取到配置文件位置,以便修改相关配置)

查找ini配置

php-fpm -i | grep ini
...
Configuration File (php.ini) Path => /usr/local/etc/php
Scan this dir for additional .ini files => /usr/local/etc/php/conf.d

安装xdebug(php版本对应的xdebug版本可以在 https://xdebug.org/download/historical 中找)

pecl install xdebug-2.5.5

安装vim

apt-get update
apt-get install vim

在php.ini中引入xdebug(后面的路径不是固定的,可能会变,也可以使用 docker-php-ext-install,docker-php-ext-enable等命令引入 引入)

vim /usr/local/etc/php/conf.d/xdebug.ini
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so

安装其他扩展

# 已有的扩展可以直接启用
docker-php-ext-enable xdebug
# 没有的扩展安装
docker-php-ext-install mbstring
docker-php-ext-install pdo_mysql
# gd
apt-get update
apt-get install libpng-dev -y
apt-get install libjpeg62-turbo-dev -y
apt-get install libfreetype6-dev -y
# imagick
apt-get install -y imagemagick php5-imagick libpng-dev libmagickwand-dev libmagickcore-dev
echo extension=imagick.so > /usr/local/etc/php/conf.d/imagick.ini
# bcmath
docker-php-ext-install bcmath

退出容器

Ctrl + p + q

使用容器建立新的images

docker commit -m "php 5.6.13 dev" -a "jin" 8428368dabbc php-jin:php-fpm5.6.13

连接nginx和php-fpm

创建网络

docker network create --driver bridge web-network

连接(以下两种方式任选一种即可)

连接方式1(已启动的容器加入)

docker network connect web-network docker-nginx

连接方式2(未启动的容器指定--network)

docker run --name="docker-php-fpm5.6.13" -v "f:/git_project":/usr/share/nginx/html --network web-network -d php-jin:php-fpm5.6.13
docker run --name="docker-nginx" -p 80:80 -v "f:/git_project":/usr/share/nginx/html -v f:/docker/php-docker/nginx-conf/conf.d/:/etc/nginx/conf.d/ --network web-network -d nginx

设置nginx的php-fpm配置

server {
        listen        80;
        server_name  xxx.com;
        root   "/usr/share/nginx/html/xxx.com/frontend/web";
        location / {
        index index.php;
        if ( !-e $request_filename )
        {
            rewrite ^/(.*)$ /index.php?r=$1 last;
        }
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   docker-php-fpm5.6.13:9000;
            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;
        }
}

标签: docker

添加新评论