1.安装docker

这里就不赘述了,已经有很多教程了

2.找一个docker镜像

我这利用的是 ohdata/swoole

 

3.安装镜像

  • 我是管理员登录的,录是D:/workspace,在这里新建文件test_swoole_server.php,代码就是swoole官网的例子

     1 <?php
     2     $http = new swoole_http_server("0.0.0.0", 9501);
     3     
     4     $http->on("start", function ($server) {
     5         echo "Swoole http server is started at http://127.0.0.1:9501\n";
     6     });
     7     
     8     $http->on("request", function ($request, $response) {
     9         $response->header("Content-Type", "text/plain");
    10         $response->end("Hello World\n".json_encode(['hello'=>'nihao'.time()]));
    11     });
    12     
    13     $http->start();

     

  • 运行命令

    PS D:\workspace> docker run  -ti -p 9501:9501 -v D:/workspace:/root/ -d ohdata/swoole:4.3.0  php /root/test_swoole_server.php

    这样就成功了,容器已经跑起来了

  • 进入容器,运行命令docker attach ID,这个ID就是容器的ID,可以用命令docker container ps查看容器ID

    win10下 使用docker搭建swoole环境

     

  • 浏览器执行 http://127.0.0.1:9501,会看到返回hello world,swoole安装成功了

相关文章:

  • 2021-09-08
  • 2021-05-03
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2019-10-24
  • 2022-02-07
猜你喜欢
  • 2021-05-12
  • 2021-04-10
  • 2022-12-23
  • 2019-02-20
  • 2022-12-23
  • 2021-12-02
相关资源
相似解决方案