1. 程式人生 > 實用技巧 >windows10 + docker利用檔案對映進行程式設計開發

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