windows10 + docker利用文件映射进行编程开发

0. 以安装swoole框架“easyswoole”举例,建议使用powershell或者cmder输入命令

 

1. 首先准备好window10专业版开启Hyper-V,然后下载并安装docker desktop,过程暂不赘述

 

2.拉取镜像  docker hub上的环境为php7.2 + swoole4.4.17+easyswoole 3.3.x

docker pull easyswoole/easyswoole3

 

 

3.拉取镜像成功之后,可以先run启动容器下看看有没有问题,没有问题就退出后查看下容器ID

PS C:\Users\renpa\Desktop> docker ps -a
CONTAINER ID        IMAGE                    COMMAND             CREATED             STATUS                        PORTS               NAMES
39fb0d2b4e5a        easyswoole/easyswoole3   "/bin/bash"         11 hours ago        Exited (127) 19 seconds ago                       awesome_meitner

 

4.获取到easyswoole容器ID之后,就把容器里面的easyswoole框架复制到宿主机里,我是直接复制到桌面的

PS C:\Users\renpa\Desktop> docker cp 39fb0d2b4e5a:/easyswoole C:\Users\renpa\Desktop

 

5.复制完成之后,就开始最重要的一步,进行文件映射,文件映射后修改宿主机的文件,docker容器里的文件也会做相应的修改。可以”非常非常快的完美进行任何环境的开发工作“,非常棒的功能。

PS C:\Users\renpa\Desktop> docker run -it -p 9501:9501 -v C:\Users\renpa\Desktop\easyswoole:/easyswoole easyswoole/easyswoole3

 

6.切记一定要手动在easyswoole的dev.php配置文件里把Temp目录改为其他路径,如:‘/Tmp‘,因为win10的docker环境中,不可把虚拟机共享目录作为easyswoole的Temp目录,否则会因为权限不足无法创建socket,产生报错

(**这个时候可以直接修改win10上easyswoole的dev.php看下是不是已经和容器内的dev.php已经同步了?**)

<?php
return [
    SERVER_NAME => "EasySwoole",
    MAIN_SERVER => [
        LISTEN_ADDRESS => 0.0.0.0,
        PORT => 9501,
        SERVER_TYPE => EASYSWOOLE_WEB_SERVER, //可选为 EASYSWOOLE_SERVER  EASYSWOOLE_WEB_SERVER EASYSWOOLE_WEB_SOCKET_SERVER,EASYSWOOLE_REDIS_SERVER
        SOCK_TYPE => SWOOLE_TCP,
        RUN_MODEL => SWOOLE_PROCESS,
        SETTING => [
            worker_num => 8,
            reload_async => true,
            max_wait_time=>3
        ],
        TASK=>[
            workerNum=>4,
            maxRunningNum=>128,
            timeout=>15
        ]
    ],
    TEMP_DIR => /Tmp,
    LOG_DIR => null
];

 

7.好了,可以直接运行docker容器里面的easyswoole框架了,大功告成!

[root@1b66ded36f2b easyswoole]# php easyswoole start
  ______                          _____                              _
 |  ____|                        / ____|                            | |
 | |__      __ _   ___   _   _  | (___   __      __   ___     ___   | |   ___
 |  __|    / _` | / __| | | | |  \___ \  \ \ /\ / /  / _ \   / _ \  | |  / _  | |____  | (_| | \__ \ | |_| |  ____) |  \ V  V /  | (_) | | (_) | | | |  __/
 |______|  \__,_| |___/  \__, | |_____/    \_/\_/    \___/   \___/  |_|  \___|
                          __/ |
                         |___/
main server                   SWOOLE_WEB
listen address                0.0.0.0
listen port                   9501
ip@eth0                       172.17.0.2
worker_num                    8
reload_async                  true
max_wait_time                 3
pid_file                      /Tmp/pid.pid
log_file                      /easyswoole/Log/swoole.log
user                          root
daemonize                     false
swoole version                4.4.17
php version                   7.2.11
easy swoole                   3.3.8-dev
develop/produce               develop
temp dir                      /Tmp
log dir                       /easyswoole/Log

 

windows10 + docker利用文件映射进行编程开发

上一篇:如何快速转化PSD为UI界面?


下一篇:PSD位置传感器