使用docker安装swoole环境
swoole Docker    2021-12-12 10:49:52    7    0    0
junjie   swoole Docker
###1.下载镜像 pull php 镜像 ``` docker pull php:7.3-alpine3.8 ``` 创建容器 ``` docker run -it --name test php:7.3-alpine3.8 sh ``` ###2.进入容器安装swoole ``` # 安装依赖的第三方包 echo http://mirrors.ustc.edu.cn/alpine/v3.7/main > /etc/apk/repositories && \ echo http://mirrors.ustc.edu.cn/alpine/v3.7/community >> /etc/apk/repositories apk --no-cache add autoconf gcc g++ make openssl openssl-dev #下载swoole pecl install swoole-4.3.1 #开启扩展 docker-php-ext-enable swoole #查看扩展 php -m #将目前环境打包成新镜像 docker commit test swoole:4.3.1 ``` ###3.创建swoole容器 ``` docker run -it --name swoole \ -p 80:80 \ -v /home/my/lujing:/pro \ swoole:4.3.1 sh ``` ###4.设置基本目录(app) ``` "autoload": { "psr-4": { "App\\": "app/" } } ``` 执行composer dump-autoload映射app目录 ###创建一个http服务 ``` $http = new Swoole\Http\Server("0.0.0.0", 80); $http->on('request', function ($request,Swoole\Http\Response $response) { $response->end("

hello

"); }); $http->start(); ```

上一篇: docker 常用命令

下一篇: RabbitMQ+PHP 教程一(Hello World)

Table of content