搭建docker+swoole+php7 的环境
2022-07-28 15:20:24
154
{{single.collect_count}}

最近在学习swoole php扩展,苦恼于其运行环境不能在win系统下运行, 但开发代码一直在win系统上,很无奈,,,,
所以就用docker来代替,舒服~
有很多相关docker的swoole镜像,很多都是基于ubuntn或centos的基础上创建的,不好的地方就是镜像体积太大了,而alpine的很小.经过不断地google,终于找到一位大神创建的docker, 很好用~~~~
以下是我的经历和填了一个坑

缩主机: Centos7

缩主机: Centos7 #file: test_swoole_server.php<?php$http = new swoole_http_server("0.0.0.0", 9501);//注意,不是127.0.0.1 而是 0.0.0.1$http->on("start", function ($server) {echo "Swoole http server is started at http://127.0.0.1:9501\n";});$http->on("request", function ($request, $response) {$response->header("Content-Type", "text/plain");$response->end("Hello World\n".json_encode(['hello'=>'nihao'.time()]));});$http->start();

docker 镜像,此镜像包括很多php扩展,例如json: https://github.com/cmptech/auto_cmp_php_docker_server

[PHP Modules]bcmathbz2calendarCorectypecurldatedomexiffileinfofilterftpgettextgmphashiconvimapjsonlibxmlmbstringmcryptmemcachedmongodbmysqlimysqlndodbcopensslpcntlpcrePDOpdo_dblibpdo_mysqlPDO_ODBCpdo_pgsqlpdo_sqlitepgsqlPharposixreadlineredisReflectionsessionshmopSimpleXMLsnmpsoapsocketsSPLsqlite3ssh2standardswoolesysvmsgsysvsemsysvshmtidytimezonedbtokenizerxmlxmlreaderxmlwriterxslZend OPcachezipzlib[Zend Modules]Zend OPcache
#运行容器, 映射端口:9501 ,存储卷 缩主机当前目录 : 容器 /root ,准备好后#运行 php7 /root/test_swoole_server.phpdocker run-ti -p 9501:9501 -v `pwd`:/root/ -d cmptech/auto_cmp_php_docker_server php7 /root/test_swoole_server.php

结果显示

[root@localhost yangqinjiang]# curl http://127.0.0.1:9501Hello World{"hello":"nihao1508839506"}

留意selinux的限制

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}