Try Open Swoole with Docker

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Bundle your own Open Swoole Docker images:


FROM php:8.2.0-cli

RUN apt-get update && apt-get install vim -y && \
    apt-get install openssl -y && \
    apt-get install libssl-dev -y && \
    apt-get install wget -y && \
    apt-get install git -y && \
    apt-get install procps -y && \
    apt-get install htop -y

RUN cd /tmp && git clone && \
    cd ext-openswoole && \
    git checkout v22.0.0 && \
    phpize  && \
    ./configure --enable-openssl --enable-hook-curl --enable-http2 --enable-mysqlnd && \
    make && make install

RUN touch /usr/local/etc/php/conf.d/openswoole.ini && \
    echo '' > /usr/local/etc/php/conf.d/zzz_openswoole.ini

RUN wget -O /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init

RUN apt-get autoremove -y && rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["/usr/local/bin/dumb-init", "--", "php"]

Save the above content into ./Dockerfile

Build php-openswoole Docker image

docker build -f ./Dockerfile -t openswoole-php .

Example Open Swoole Application


use OpenSwoole\Http\Server;
use OpenSwoole\Http\Request;
use OpenSwoole\Http\Response;

$server = new OpenSwoole\HTTP\Server("", 9501);

$server->on("Start", function(Server $server)
    echo "OpenSwoole http server is started at\n";

$server->on("Request", function(Request $request, Response $response)
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");


Save the above code into ./server.php

Try your Open Swoole Application

On Linux or MacOS:

docker run --rm -p 9501:9501 -v $(pwd):/app -w /app openswoole-php server.php

Or on Windows:

docker run --rm -p 9501:9501 -v C:/YOUR_DIR/:/app -w /app openswoole-php server.php

You are able to access the hello world Open Swoole application from

Interested with Open Swoole? Get Started with Open Swoole now

Use Docker Images

You are free to build your own Swoole Docker image but there is a Official OpenSwoole Docker images hosted on the hub as well, for example:

Last updated on February 7, 2023