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

How to install swoole in docker

Release: 2019-12-06 09:47:56
Original
6589 people have browsed it

How to install swoole in docker

1、下载镜像

pull php 镜像

docker pull php:7.3-alpine3.8
Copy after login

创建容器

docker run -it --name test php:7.3-alpine3.8  sh
Copy after login

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
Copy after login

3、创建swoole容器

docker run -it --name swoole \
-p 80:80 \
-v /home/my/lujing:/pro \
swoole:4.3.1 sh
Copy after login

4、设置基本目录(app)

"autoload": {
        "psr-4": {
            "App\\": "app/"
        }
    }
Copy after login

执行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("<h1>hello</h1>");
});
$http->start();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template