#### 1、下载镜像
1、docker pull nginx
2、docker pull php:7.1.0-fpm
#### 2、建立docker映射目录
1、mkdir -p /docker/www
2、mkdir -p /docker/nginx/conf.d
#### 3、编辑nginx配置文件
#vim /docker/nginx/conf.d/default.conf
\# 以下为示例内容
server {
listen 80 default\_server;
server\_name \_;
root /usr/share/nginx/html;
location / {
index index.html index.htm index.php;
try\_files $uri $uri/ /index.php$is\_args$query\_string;
autoindex off;
}
location ~ \\.php(.\*)$ {
root /var/www/html/;
fastcgi\_pass 172.17.0.2:9000;
fastcgi\_index index.php;
fastcgi\_split\_path\_info ^((?U).+\\.php)(/?.+)$;
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;
fastcgi\_param PATH\_INFO $fastcgi\_path\_info;
fastcgi\_param PATH\_TRANSLATED $document\_root$fastcgi\_path\_info;
include fastcgi\_params;
}
}
#### 4、启动PHP镜像
docker run -p 80:80 --name mynginx -v /docker/www:/usr/share/nginx/html -v /docker/nginx/conf.d:/etc/nginx/conf.d --privileged=true -d nginx
查看php镜像的ip地址
docker inspect --format='{{.NetworkSettings.IPAddress}}' myphp
172.17.0.2
修改default.conf配置文件,使fastcgi\_pass的值为 172.17.0.2:9000
vim /docker/nginx/conf.d/default.conf
fastcgi\_pass 172.17.0.2:9000;
#### 5、启动nginx镜像
docker run -p 80:80 --name mynginx -v /docker/www:/usr/share/nginx/html -v /docker/nginx/conf.d:/etc/nginx/conf.d --privileged=true -d nginx
#### 6、测试Nginx和php是否正常
echo "test" > /docker/www/index.html
echo "<?php phpinfo();?>" > /docker/www/info.php
说明:docker 启动是使用一个或多个 -v 参数,使容器内的目录映射到宿主机上,每次修改不必进入宿主机操作
#### 7、mysql 和redis/memcached等涉及数据存储的应用不安装docker容器内,防止容器删除数据丢失
mysql
#sudo apt-get install mysql-server
#sudo apt isntall mysql-client
redis
#sudo apt-get install redis-server
#sudo service redis-server start
#### 8、php docker容器安装php相应的拓展
#进入运行中的容器
#docker exec -it IMAGEID /bin/bash
#docker-php-ext-install bcmath dba exif mysqli pdo\_mysql sysvsem sysvshm pdo\_mysql
#验证
#php -m | grep -i 'mysql'