前期工作
一、在宿主机创建文件夹
D:wnmpmysql57-conf
D:wnmpmysql57-log
D:wnmp
ginx110-conf
D:wnmp
ginx110-log
D:wnmpphp71-conf
D:wnmpphp71-log
D:wnmpwww
二、新建hyper-v.cmd文件,内容如下:(如何window10家庭版需要如下操作,如果是专业版请跳过)
pushd "%~dp0" dir /b %SystemRoot%servicingPackages*Hyper-V*.mum >hyper-v.txt for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%servicingPackages\%%i" del hyper-v.txt Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL
二(1)、修改注册表伪装专业版
win+R 运行regedit
计算机HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersion
EditionID修改成Professional
三、下载docker安装包
下载 Docker Windows 18.06.1-ce-win73下载
下载完安装,一路确定就可以
安装完,右键右下角任务栏的小鱼点击settings,选中shared Drives,选中D盘,点击apply
四、打开hyper-v管理器
hyper-v设置
虚拟硬盘更改路径 D:Hyper-VVirtual 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:wnmpmysql57-log docker cp mysql57:/etc/mysql D:wnmpmysql57-conf docker stop mysql57 docker rm mysql57 docker run -d -v D:wnmpmysql57-log:/var/log/mysql/ -v D:wnmpmysql57-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:wnmpwww:/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:wnmpphp71-conf docker cp php71:/usr/local/var/log D:wnmpphp71-log docker cp php71:/var/www/html D:wnmpwww docker stop php71 docker rm php71 docker run -d -v D:wnmpphp71-conf:/usr/local/etc -v D:wnmpphp71-log:/usr/local/var/log -v D:wnmpwww:/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 ginx110-conf docker cp nginx110:/var/log/nginx/ D:wnmp ginx110-log docker cp nginx110:/var/www/html D:wnmpwww docker stop nginx110 docker rm nginx110 docker run -d -p 80:80 -v D:wnmpwww:/var/www/html -v D:wnmp ginx110-conf:/etc/nginx/ -v D:wnmp ginx110-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
ginx-confconf.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; } }
最后,多版本安装也是一样的就不一一举例了,步骤都是一样,预祝大家安装成功!