win10 docker toolsbox Tutorial for Building php Development Environment

  • 2021-07-06 12:05:24
  • OfStack

Download image


docker pull mysql:5.7 
docker pull php:7.2-fpm
docker pull nginx
docker pull redis:3.2

Set up shared files

Host creates directory


E:\wnmp\mysql57\conf
E:\wnmp\mysql57\log
E:\wnmp\php72\conf
E:\wnmp\php72\conf
E:\wnmp\nginx\conf
E:\wnmp\nginx\conf
E:\wnmp\www

vmware Setting up File Sharing

As shown

Setup completes docker-machine restart default on Docker Quickstart Termina

Installing Mysql


docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --name mysql57 mysql:5.7

Copy configuration file


PS C:\Windows\system32> docker cp mysql57:/var/log/mysql E:\wnmp\mysql57\log
PS C:\Windows\system32> docker cp mysql57:/etc/mysql E:\wnmp\mysql57\conf

Reinstall mysql and specify the configuration file


PS C:\WINDOWS\system32> docker stop mysql57
mysql57
PS C:\WINDOWS\system32> docker rm mysql57
mysql57
PS 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

Initialize the database


docker exec -ti mysql57 /bin/bash
mysql_secure_installation 
# View Mysql Status 
root@d7bd0712bcf8:/# mysql -uroot -proot
mysql: [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 6
Server 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 its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Installing 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

Copy configuration file


PS C:\Windows\system32> docker cp php72:/usr/local/etc E:\wnmp\php72\conf
PS C:\Windows\system32> docker cp php72:/usr/local/var/log E:\wnmp\php72\log
PS C:\Windows\system32> docker cp php72:/var/www/html E:\wnmp\www

Reinstall PHP and specify the configuration file


PS C:\WINDOWS\system32> docker stop php72
php72
PS C:\WINDOWS\system32> docker rm php72
php72
docker 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
#  View PHP Version 
PS C:\Windows\system32> docker exec -ti php72 /bin/bash
root@742150f14d8a:/var/www/html# php -v
PHP 7.2.23 (cli) (built: Oct 5 2019 00:31:47) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
Ngixn

Installation

PS C:\WINDOWS\system32 > docker run -d -p 80:80 --link php72:phpfpm --name nginx nginx:latest

Copy configuration file


PS C:\Windows\system32> docker cp nginx:/etc/nginx/ E:\wnmp\nginx\conf
PS C:\Windows\system32> docker cp nginx:/var/log/nginx/ E:\wnmp\nginx\log

Reinstall and specify the configuration file


E:\wnmp\mysql57\conf
E:\wnmp\mysql57\log
E:\wnmp\php72\conf
E:\wnmp\php72\conf
E:\wnmp\nginx\conf
E:\wnmp\nginx\conf
E:\wnmp\www
0

PHP Extension Installation


E:\wnmp\mysql57\conf
E:\wnmp\mysql57\log
E:\wnmp\php72\conf
E:\wnmp\php72\conf
E:\wnmp\nginx\conf
E:\wnmp\nginx\conf
E:\wnmp\www
1

Configure test domain name


E:\wnmp\mysql57\conf
E:\wnmp\mysql57\log
E:\wnmp\php72\conf
E:\wnmp\php72\conf
E:\wnmp\nginx\conf
E:\wnmp\nginx\conf
E:\wnmp\www
2

The above are all installation configurations and tests. Finally, of course, we need to add these docker containers to the automatic startup


docker container update --restart=always php72
docker container update --restart=always mysql57
docker container update --restart=always nginx
docker container update --restart=always redis

Summarize


Related articles: