1.查找镜像,推荐以下两种

docker search nginx
https://hub.docker.com/
2.下载镜像


docker pull php:7.2-fpm
docker pull nginx

3.创建文件夹和index.php文件


mkdir -p /www/conf.d /www/default
echo "<php" > index.php && echo "phpinfo();" >> index.php


4.拷贝容器文件


docker run --name nginx -d nginx
docker cp nginx:/etc/nginx/conf.d/default.conf /www/conf.d
5.停止并删除容器



docker stop nginx


docker rm nginx
6.启动php容器

docker run --name php7.2 -d -v /www/default:/www/default php:7.2-fpm
7.查看php容器ip地址

docker inspect php7.2 | grep IPAddress
8.编辑nginx配置文件

vi /www/conf.d/default.conf
server {

    listen       80;

    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /www/default;
        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           /www/default;
        fastcgi_pass   172.17.0.2:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
9.启动nginx容器

docker run --name nginx -p 80:80 -d -v /www/default:/www/default -v /www/conf.d:/etc/nginx/conf.d nginx
10.访问ip或者网址显示phpinfo