前期工作
一、在宿主机创建文件夹
D:\wnmp\mysql57-conf
D:\wnmp\mysql57-log
D:\wnmp\nginx110-conf
D:\wnmp\nginx110-log
D:\wnmp\php71-conf
D:\wnmp\php71-log
D:\wnmp\www
二、新建hyper-v.cmd文件,内容如下:(如何window10家庭版需要如下操作,如果是专业版请跳过)
pushd "%~dp0" dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i" del hyper-v.txt Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL
二(1)、修改注册表伪装专业版
win+R 运行regedit
计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
EditionID修改成Professional
三、下载docker安装包
下载 Docker Windows 18.06.1-ce-win73下载
下载完安装,一路确定就可以
安装完,右键右下角任务栏的小鱼点击settings,选中shared Drives,选中D盘,点击apply
四、打开hyper-v管理器
hyper-v设置
虚拟硬盘更改路径 D:\Hyper-V\Virtual Hard Disks
虚拟机更改路径 D:\Hyper-V
ps:如下操作命令行必须以管理员运行黑窗口
mysql:
docker pull mysql:5.7 docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --name mysql57 mysql:5.7 docker exec -ti mysql57 /bin/bash docker cp mysql57:/var/log/mysql D:\wnmp\mysql57-log docker cp mysql57:/etc/mysql D:\wnmp\mysql57-conf docker stop mysql57 docker rm mysql57 docker run -d -v D:\wnmp\mysql57-log:/var/log/mysql/ -v D:\wnmp\mysql57-conf:/etc/mysql/ -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --name mysql mysql:5.7 docker exec -ti mysql57 /bin/bash mysql_secure_installation 数据库初始化 apt update apt-get install vim
php:
docker pull php:7.1-fpm docker run -d -v D:\wnmp\www:/var/www/html -p 9000:9000 --link mysql57:mysql --name php71 php:7.1-fpm docker exec -ti php71 /bin/bash docker cp php71:/usr/local/etc D:\wnmp\php71-conf docker cp php71:/usr/local/var/log D:\wnmp\php71-log docker cp php71:/var/www/html D:\wnmp\www docker stop php71 docker rm php71 docker run -d -v D:\wnmp\php71-conf:/usr/local/etc -v D:\wnmp\php71-log:/usr/local/var/log -v D:\wnmp\www:/var/www/html -p 9000:9000 --link mysql57:mysql --name php71 php:7.1-fpm docker exec -ti php71 /bin/bash apt update apt-get install vim
nginx:
docker pull nginx:1.10.3 docker run -d -p 80:80 --link php71:phpfpm --name nginx110 nginx:1.10.3 docker exec -ti nginx110 /bin/bash docker cp nginx110:/etc/nginx/ D:\wnmp\nginx110-conf docker cp nginx110:/var/log/nginx/ D:\wnmp\nginx110-log docker cp nginx110:/var/www/html D:\wnmp\www docker stop nginx110 docker rm nginx110 docker run -d -p 80:80 -v D:\wnmp\www:/var/www/html -v D:\wnmp\nginx110-conf:/etc/nginx/ -v D:\wnmp\nginx110-log:/var/log/nginx/ --link php71:phpfpm --name nginx nginx110
redis:
docker pull redis docker run -p 6379:6379 -d redis redis-server
安装redis非自带扩展
docker exec -it php71 /bin/bash curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/3.1.3.tar.gz tar xfz /tmp/redis.tar.gz rm -r /tmp/redis.tar.gz mkdir -p /usr/src/php/ext mv phpredis-3.1.3 /usr/src/php/ext/redis docker-php-ext-install redis docker restart php71
安装php自带扩展
docker exec -it php /bin/bash至目录下 cd /usr/local/bin ./docker-php-ext-install pdo_mysql ./docker-php-ext-install mysql docker restart php71
宿主机重启自动启动容器
docker container update --restart=always php71 docker container update --restart=always mysql57 docker container update --restart=always nginx110 docker container update --restart=always redis
修改nginx配置文件(D:\wnmp\nginx-conf\conf.d)
server { listen 80; server_name www.csdx.com; root /var/www/html/caishangdaxue/public; index index.php index.html index.htm; access_log /etc/nginx/access.log; error_log /var/log/nginx/error.log; location / { try_files $uri $uri/ /index.php$is_args$args; if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last; break; } } location ~ \.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; fastcgi_pass 10.0.75.1:9000; try_files $uri = 404; } location ~ /\.(ht|svn|git) { #deny all; } }
最后,多版本安装也是一样的就不一一举例了,步骤都是一样,预祝大家安装成功!