下载镜像
docker pull mysql:5.7 docker pull php:7.2-fpmdocker pull nginxdocker pull redis:3.2
设置共享文件
宿主机创建目录
E:/wnmp/mysql57/confE:/wnmp/mysql57/logE:/wnmp/php72/confE:/wnmp/php72/confE:/wnmp/nginx/confE:/wnmp/nginx/confE:/wnmp/www
vmware设置文件共享
如图
设置完成在Docker Quickstart Termina 执行 docker-machine restart default
安装Mysql
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --name mysql57 mysql:5.7
复制配置文件
PS C:/Windows/system32> docker cp mysql57:/var/log/mysql E:/wnmp/mysql57/logPS C:/Windows/system32> docker cp mysql57:/etc/mysql E:/wnmp/mysql57/conf
重新安装mysql并指定配置文件
PS C:/WINDOWS/system32> docker stop mysql57mysql57PS C:/WINDOWS/system32> docker rm mysql57mysql57PS C:/WINDOWS/system32> docker run -d -v /wnmp/mysql57/log:/var/log/mysql/ -v /wnmp/mysql57/conf:/etc/mysql/ -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --name mysql57 mysql:5.7
初始化数据库
docker exec -ti mysql57 /bin/bashmysql_secure_installation #查看Mysql状态root@d7bd0712bcf8:/# mysql -uroot -prootmysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or /g.Your MySQL connection id is 6Server version: 5.7.28 MySQL Community Server (GPL)Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
安装PHP
PS C:/WINDOWS/system32> docker run -d -v /wnmp/www:/var/www/html -p 9000:9000 --link mysql57:mysql --name php72 php:7.2-fpm
复制配置文件
PS C:/Windows/system32> docker cp php72:/usr/local/etc E:/wnmp/php72/confPS C:/Windows/system32> docker cp php72:/usr/local/var/log E:/wnmp/php72/logPS C:/Windows/system32> docker cp php72:/var/www/html E:/wnmp/www
重新安装PHP并指定配置文件
PS C:/WINDOWS/system32> docker stop php72php72PS C:/WINDOWS/system32> docker rm php72php72docker run -d -v /wnmp/php72/conf/etc:/usr/local/etc -v /wnmp/php72/log:/usr/local/var/log -v /wnmp/www:/var/www/html -p 9000:9000 --link mysql57:mysql --name php72 php:7.2-fpm# 查看PHP版本PS C:/Windows/system32> docker exec -ti php72 /bin/bashroot@742150f14d8a:/var/www/html# php -vPHP 7.2.23 (cli) (built: Oct 5 2019 00:31:47) ( NTS )Copyright (c) 1997-2018 The PHP GroupZend Engine v3.2.0, Copyright (c) 1998-2018 Zend TechnologiesNgixn
安装
PS C:/WINDOWS/system32> docker run -d -p 80:80 --link php72:phpfpm --name nginx nginx:latest
复制配置文件
PS C:/Windows/system32> docker cp nginx:/etc/nginx/ E:/wnmp/nginx/confPS C:/Windows/system32> docker cp nginx:/var/log/nginx/ E:/wnmp/nginx/log
重新安装并指定配置文件
PS C:/WINDOWS/system32> docker stop nginxnginxPS C:/WINDOWS/system32> docker rm nginxnginxPS C:/WINDOWS/system32> docker run -d -p 80:80 -v /wnmp/www:/var/www/html -v /wnmp/nginx/conf/nginx:/etc/nginx/ -v /wnmp/nginx/log:/var/log/nginx/ --link php72:phpfpm --name nginx nginx#浏览器访问 http://192.168.99.100/ 验证成功Redisdocker run -p 6379:6379 -d redis:3.2 redis-server
PHP扩展安装
redisPS C:/Windows/system32> docker exec -ti php72 /bin/bashroot@742150f14d8a:/var/www/html# pecl install -o -f redis#安装完成,加入Ini配置 此时docker下的redis配置 在E:/wnmp/php72/conf/etc/php/conf.d/docker-php-ext-sodium.ini# 重启php
配置测试域名
#E:/wnmp/nginx/conf/nginx/conf.d目录下新建test.conf#E:/wnmp/www目录新建test目录。目录下新建index.php 输出phpinfo;server { listen 80; server_name test.com; #charset koi8-r; access_log /var/log/nginx/host.access.log main; location / { root /var/www/html/test; 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 /var/www/html/test; fastcgi_pass 192.168.99.100:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$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; }}#nginx重新加载配置 或者重启。#本地host解析域名test.com 访问 显示phpinfo正常
以上为所有安装配置以及测试。当然最后我们需要将这些docker容器加入到自动启动中
docker container update --restart=always php72docker container update --restart=always mysql57docker container update --restart=always nginxdocker container update --restart=always redis
总结
以上就是小编给大家介绍的win10 docker-toolsbox 搭建php开发环境的教程,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!