docker部署web环境只需要几分钟(如果网速够快)。
第一步:
php部署
1、拉取php-fpm
docker pull php:7.1-fpm
2、部署,并启动php
docker run --name myphp-fpm -v ~/nginx/www:/usr/share/nginx/html -d php:7.1-fpm
第二步
nginx部署
1、拉取nginx
$ docker pull nginx:latest
2‘、部署nginx,并启动nginx
docker run --name runoob-php-nginx -p 80:80 -d \
-v ~/nginx/www:/usr/share/nginx/html:ro \
--link myphp-fpm:php \
nginx
第三步
关联php
1、找到docker根目录,创建default.conf配置文件,内容如下:
server {
listen 80;
listen [::]:80;
server_name localhost;
#charset koi8-r;
#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$ {
fastcgi_pass 172.17.0.2:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
#fastcgi_param SCRIPT_NAME $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;
#}
}
2、使用docker copy命令复制到nginx配置目录
docker cp ./default.conf nginx-test:/etc/nginx/conf.d/default.conf
3、进入Nginx容器,并重新加载nginx配置
docker exec -it runoob-php-nginx bash
service nginx reload
配置完就可以运行php了。
第四步
1、拉取mysql
docker pull mysql:latest
2、部署mysql
docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
3、登陆mysql并修改密码
docker exec -it mysql-test bash
mysql -uroot -p123456
mysql> use mysql
mysql> update user set password=password('123456') where user='root' and host='localhost';
mysql> flush privileges;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
mysql> flush privileges;
部署完毕