Home  >  Article  >  PHP Framework  >  How to install swoole in docker

How to install swoole in docker

尚
Original
2019-12-06 09:47:566434browse

How to install swoole in 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("4a249f0d628e2318394fd9b75b4636b1hello473f0a7621bec819994bb5020d29372a");
});
$http->start();

The above is the detailed content of How to install swoole in docker. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What swoole can doNext article:What swoole can do