拉取镜像
docker pull phpswoole/swoole:latest
测试镜像环境:
docker run --rm phpswoole/swoole:latest "php -m"
docker run --rm phpswoole/swoole:latest "php --ri swoole"
docker run --rm phpswoole/swoole:latest "composer --version"
启动容器
docker run --rm -p 8000:9501 --name swoole -v /www/swoole:/var/www phpswoole/swoole:latest
新建/www/swoole/server.php文件
<?php
// 创建Swoole HTTP服务器,监听9501端口
$server = new Swoole\Http\Server("0.0.0.0", 9501);
$server->on("request", function ($request, $response) {
$response->header("Content-Type", "text/plain");
$response->end("Hello, Swoole!");
});
$server->start();
?>
容器里执行:
php server.php
打开新窗口测试:
curl http://127.0.0.1:8000