一、创建Dockerfile
FROM phpswoole/swoole # COPY ./www/ /var/www/
二、同级目录下创建docker-composer.yaml
services: phpswoole-server: container_name: phpswoole-server image: phpswoole/swoole ports: - "8000:9501" environment: AUTORELOAD_PROGRAMS: "swoole" AUTORELOAD_ANY_FILES: 1 volumes: - ./www:/var/www
三、当前目录下创建www/server.php
<?php declare(strict_types=1); $http = new Swoole\Http\Server("0.0.0.0", 9501); $http->on( "request", function (Swoole\Http\Request $request, Swoole\Http\Response $response) { $response->end( <<<EOT Hello, world! EOT ); } );$http->start();
四、启动服务
docker-compose -f "docker-compose.yml" up --build --force-recreate -d
五、验证服务
curl http://127.0.0.1:8000
标签:phpswoole,www,http,swoole,server,docker From: https://www.cnblogs.com/chulx/p/16602865.html