# 安装Dockerhttps://docs.docker.com/get-docker/# 安装Docker Composehttps://docs.docker.com/compose/install/# CentOS安装Dockerhttps://mp.weixin.qq.com/s/nHNPbCmdQs3E5x1QBP-ueAmkdir phpcd php
mkdir -p nginx/conf.d
server { listen 80; listen [::]:80; server_name localhost; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.php index.html index.htm; } #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 php:9000; fastcgi_index index.php; 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; #}}mkdir htmlecho 'home' > html/index.htmlecho "<?php echo 'hello';" > html/hello.php
创建docker-compose.yaml文件:
services: nginx: image: nginx:latest container_name: nginx ports: - 8080:80 - 8443:443 volumes: - ./nginx/conf.d:/etc/nginx/conf.d - ./html:/usr/share/nginx/html depends_on: - php links: - php php: image: php:8-fpm container_name: php privileged: true ports: - 9000:9000 volumes: #- ./php/php.ini:/usr/local/etc/php/php.ini - ./html:/usr/share/nginx/htmldocker-compose up -d
docker ps
docker-compose down
docker rmi nginx:latest php:8-fpm
docker pull php:8-fpmdocker pull nginx:latest
# 运行php容器:docker run -it -d \ --name php \ -p 9000:9000 \ -v ./html:/usr/share/nginx/html \ php:8-fpm# 运行nginx容器:docker run -it -d \ --name nginx \ -p 8080:80 \ -p 8443:443 \ -v ./nginx/conf.d:/etc/nginx/conf.d \ -v ./html:/usr/share/nginx/html \ --link php \ nginx:latestdocker ps
docker stop nginx php
docker rm nginx php
docker rmi nginx:latest php:8-fpm
详见:https://github.com/docker-library/php
wget https://www.php.net/distributions/php-8.4.8.tar.xz
创建Dockerfile文件:
FROM alpine:latestADD php-8.4.8.tar.xz /root/RUN cp /etc/apk/repositories /etc/apk/repositories-bak; \ sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories; \ apk add --no-cache gcc g++ make autoconf pkgconfig libxml2-dev openssl-dev sqlite-dev bzip2-dev curl-dev libpng-dev jpeg-dev freetype-dev gettext-dev gmp-dev icu-dev oniguruma-dev libxslt-dev linux-headers libtool libnsl-dev libc-dev pcre-dev zlib-dev libmcrypt-dev; \ ldconfig; \ cd /root/php-8.4.8; \ ./configure --prefix=/usr/local/php \ --with-bz2 \ --with-curl \ --enable-gd \ --with-jpeg \ --with-freetype \ --with-gettext \ --with-gmp \ --with-libdir=lib64 \ --with-mysqli \ --with-openssl \ --with-pdo-mysql \ --with-xsl \ --with-zlib \ --enable-fpm \ --enable-bcmath \ --enable-calendar \ --enable-exif \ --enable-intl \ --enable-mbstring \ --enable-pcntl \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvsem; \ make && make install; \ rm -rf /root/php-8.4.8; \ cd /usr/local/php/etc; \ cp php-fpm.conf.default php-fpm.conf; \ cp php-fpm.d/www.conf.default php-fpm.d/www.conf; \ #sed -i 's/;daemonize = yes/daemonize = no/g' php-fpm.conf; \ sed -i 's/listen = 127.0.0.1:9000/listen = 0.0.0.0:9000/g' php-fpm.d/www.conf#CMD ["/usr/local/php/sbin/php-fpm"]CMD ["/usr/local/php/sbin/php-fpm","-F"]
说明:修改php-fpm以前台运行方式1:将/usr/local/php/etc/php-fpm.conf文件的“;daemonize = yes”修改为“daemonize = no”方式2:/usr/local/php/sbin/php-fpm -Fdocker build -t php:v1 .
# 运行php容器:docker run -it -d \ --name php \ -p 9000:9000 \ -v ./html:/usr/share/nginx/html \ php:v1# 运行nginx容器:docker run -it -d \ --name nginx \ -p 8080:80 \ -p 8443:443 \ -v ./nginx/conf.d:/etc/nginx/conf.d \ -v ./html:/usr/share/nginx/html \ --link php \ nginx:latestdocker ps
docker stop nginx php
docker rm nginx php
docker rmi nginx:latest php:v1
假设当前ip为192.168.186.128浏览器访问:http://192.168.186.128:8080http://192.168.186.128:8080/hello.phphttps://www.php.net/https://github.com/docker-library/phphttps://github.com/docker-library/nginxhttps://hub.docker.com/_/phphttps://hub.docker.com/_/nginx
本文链接:https://www.kinber.cn/post/6138.html 转载需授权!
推荐本站淘宝优惠价购买喜欢的宝贝:

支付宝微信扫一扫,打赏作者吧~
