1、拉取镜像命令
docker pull php:7.2.0-cli-alpine
2、启动容器并执行命令
docker run -it --name php-cli php:7.2.0-cli-alpine php -m
3、查看container 列表命令
docker ps
4、删除某一container
docker rm php-cli
5、挂载文件并执行PHP脚本
docker run -it --name php-cli -v /root/php/:/script/ php:7.2.0-cli-alpine php /script/index.php
6、让容器后台运行
docker run -d --name php-fpm --rm php:7.2.0-fpm-alpine3.6
7、挂载文件并映射端口
docker run -d --name php-apa -p 80:80 -v /root/php/:/usr/local/apache2/htdocs/ httpd:2.4-alpine
8、查看 apahce 配置文件
docker exec -it php-apa cat /usr/local/apache2/conf/httpd.conf
9、copy apahce 配置文件
docker cp php-apa:/usr/local/apache2/conf/httpd.conf /root/php/conf/
10、php-fpm 配合apache
Apache 配置文件修改:
# DocumentRoot "/usr/local/apache2/htdocs" <VirtualHost *:80> DocumentRoot "/usr/local/apache2/htdocs" ServerName localhost ProxyRequests Off ProxyPassMatch ^/(.*.php)$ fcgi://172.17.0.2:9000/php/$1 <Directory "/usr/local/apache2/htdocs"> Options none AllowOverride none Require all granted </Directory> </VirtualHost> LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_connect_module modules/mod_proxy_connect.so #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so #LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
配置php-fpm:docker run --rm -d -v /root/php/:/php/ --name php-fpm php:7.2.0-fpm-alpine3.6
配置php-apache:docker run -d -p 80:80 -v /root/php/:/usr/local/apache2/htdocs/ -v /root/conf/httpd.conf:/usr/local/apache2/conf/httpd.conf --name php-apache httpd:2.4-alpine
/var/spool/cron/crontabs/root