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

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  /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