一、php docker
1、创建php Docker, Dockerfile文件如下
- FROM php:7.3.7-fpm
-
- RUN mkdir -p /php/myphp
2、启动脚本start.sh,其中会安装php mysql驱动
- #!/bin/bash
- rm -rf myphp
- unzip myphp.zip
- cp .env.pro ./myphp
- cp .env ./myphp
-
- docker rm -f myphp
- docker build -t myphp .
- docker run -d --network lt-pro-net --name myphp --privileged=true -p 19000:9000 --restart=always -v /home/docker/myphp/:/php/myphp/ -v /home/docker/myphp/php.ini:/usr/local/etc/php/php.ini myphp:latest
-
- chmod -R 777 /home/docker/myphp/
- #docker-php-ext-install pdo pdo_mysql
- docker exec -it myphp bash -c "docker-php-ext-install pdo pdo_mysql"
-
- docker restart myphp
其中.env文件指定pro环境,.env.pro中为配置
php.ini需要设置mysqlnd
二、php nginx docker
1、创建php nginx 的Docker脚本 Dockerfile文件如下
- FROM nginx:1.19.0
-
- ENV TZ='Asia/Shanghai'
- #one app create one log path
- RUN mkdir -p /log/myphp
2、php nginx配置如下 myphp.conf
- server {
- listen 9001;
- server_name localhost;
- root /php/myphp/public;
- access_log /log/myphp/access-test.log main;
- error_log /log/myphp/error-test.log error;
- client_max_body_size 0;
- client_header_buffer_size 32k;
- large_client_header_buffers 4 16k;
- client_header_timeout 1m;
- client_body_timeout 120s;
-
- location / {
- add_header Access-Control-Allow-Origin * always;
- add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS, PUT, DELETE';
- add_header Access-Control-Allow-Headers 'token,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
- index index.php index.html index.htm;
- try_files $uri $uri/ /index.php?$query_string;
- }
-
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- location ~ \.php$ {
- fastcgi_pass myphp:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- }
- }
3、执行脚本start.sh
- #!/bin/bash
- docker rm -f lt-php-nginx
- docker build -t lt-php-nginx .
- docker run --name lt-php-nginx --privileged=true --restart=always \
- --network lt-pro-net \
- -v /home/docker/app/php-nginx/conf.d:/etc/nginx/conf.d \
- -p 9001:9001\
- -v /home/docker/myphp:/php/myphp \
- -v /home/docker/myphp/log:/log/myphp \
- --link myphp:myphp \
- -d nginx