Skip to main content

Docker 创建 Nginx 和 php-fpm环境

Docker创建Nginx和php-fpm环境


docker image pull nginx

docker image pull php:fpm

docker container run -d -it --name nginx -p 80:80 nginx

docker container run -d -it --name php-fpm -v /www:/www --network=container:nginx php:fpm


docker container run -d -it --name php-fpm -v /home/develop/service:/www --network=container:nginx php:fpm


docker container run -d \
--name php-fpm \
-v /data/server/pm/pm_service:/www \
-v /data/server/pm/logs:/logs \
-p 9000:9000 \
php:7.4.21-fpm



cd /usr/local/bin
./docker-php-ext-install mysqli

echo '

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /www;
        index  index.html index.htm index.php;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /service/www/$fastcgi_script_name;
        include        fastcgi_params;
    }
}

' > default.conf

docker cp default.conf nginx:/etc/nginx/conf.d/default.conf

docker exec nginx nginx -s reload

mkdir /www

echo '<?php echo time();' > /www/test.php

curl http://127.0.0.1/test.php