本地拉取镜像:
docker pull phpswoole/swoole:4.5.9-php7.4
测试镜像环境:
docker run --rm phpswoole/swoole:4.5.9-php7.4 "php -m"
docker run --rm phpswoole/swoole:4.5.9-php7.4 "php --ri swoole"
docker run --rm phpswoole/swoole:4.5.9-php7.4 "composer --version"
服务代码 D:\docker\swoole\server.php
<?php
$http = new Swoole\Http\Server('0.0.0.0', 9501);
$http->on('Request', function ($request, $response) {
$response->header('Content-Type', 'text/html; charset=utf-8');
$response->end('<h1>Hello Swoole. #' . rand(1000, 9999) . '</h1>');
});
$http->start();
启动容器
docker run --rm -p 8000:9501 --name swoole -v D:\docker\swoole:/var/www phpswoole/swoole:4.5.9-php7.4
浏览器查看localhost:8000
查看所有容器
docker ps -a
进入容器
docker exec -it [CONTAINER ID] bash
运行服务代码
php server.php
本地镜像phpswoole/swoole:4.5.9-php7.4
标签到个人线上仓库18061808047/swoole
的default标签
docker tag phpswoole/swoole:4.5.9-php7.4 18061808047/swoole:default
本地镜像推送到线上
docker push 18061808047/swoole:default
docker hub仓库: