Try Swoole with Docker


FROM php:7.4.2-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 swoole-src && \
    git checkout v4.6.4 && \
    phpize  && \
    ./configure --enable-openssl && \
    make && make install

RUN touch /usr/local/etc/php/conf.d/swoole.ini && \
    echo '' > /usr/local/etc/php/conf.d/swoole.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-swoole Docker image

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

Example Swoole Applicaiton

$http = new Swoole\HTTP\Server("", 9501);

$http->on('start', function ($server) {
    echo "Swoole http server is started at\n";

$http->on('request', function ($request, $response) {
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");


Save the above code into ./server.php

Try your Swoole Application

On Linux or MacOS:

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

Or on Windows:

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

You are able to access the hello world Swoole applicaiton from

Interested with Swoole? Get Started with Swoole now!