Home

Awesome

Docker Image for Swoole

Twitter Discord Docker Pulls License

This image is built for general-purpose. We have different examples included in this Git repository to help developers to get familiar with the image and Swoole.

You can get the image from here.

Table of Contents

Feature List

NOTES

  1. The auto-reloading feature is supported for non-Alpine images only.
  2. To disable extension pdo_mysql and/or Redis, please check section Disable Installed/Enabled PHP Extensions.

How to Use This Image

The phpswoole/swoole image is built using the official PHP image as base image, with a few changes. For basic usage, please check the description section of the official PHP image.

How to Install More PHP Extensions

Same as in the official PHP image, most PHP extensions can be installed/configured using built-in helper scripts docker-php-ext-configure, docker-php-ext-install, docker-php-ext-enable, and docker-php-source. Here are some examples.

# To install the MySQL extensions.
# NOTE: The pdo_mysql extension is included in 4.8.12+ and 5.0.1+ images.
FROM phpswoole/swoole:4.7-php7.4-alpine

RUN docker-php-ext-install mysqli pdo_mysql
# To install the Redis extension.
# NOTE: The Redis extension is included in 4.8.12+ and 5.0.1+ images.
FROM phpswoole/swoole:4.7-php7.4-alpine

RUN set -ex \
    && pecl channel-update pecl.php.net \
    && yes no | pecl install redis-stable \
    && docker-php-ext-enable redis
# To install the Couchbase extension.
FROM phpswoole/swoole:4.8-php7.4-alpine

RUN set -ex \
    && apk update \
    && apk add --no-cache libcouchbase=2.10.6-r0 \
    && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS libcouchbase-dev=2.10.6-r0 zlib-dev \
    && pecl update-channels \
    && pecl install couchbase-2.6.2 \
    && docker-php-ext-enable couchbase \
    && apk del .build-deps \
    && rm -rf /var/cache/apk/* /tmp/* /usr/share/man /usr/src/php.tar.xz*

Disable Installed/Enabled PHP Extensions

Since 4.8.12+ and 5.0.1+, PHP extensions pdo_mysql and Redis are installed and enabled by default. If you want to disable them, you can use the following commands in your Dockerfile.

FROM phpswoole/swoole:4.8-alpine

RUN set -ex && \
    rm -f "$(php-config --ini-dir)/docker-php-ext-pdo_mysql.ini" && \
    rm -f "$(php-config --ini-dir)/docker-php-ext-redis.ini"

Note that above commands will remove the corresponding configuration files for the extensions, but won't remove the extensions themselves.

More Examples

Following examples are for non-Alpine images only. We don't have examples included for the Alpine images.

You can use the image to serve an HTTP/WebSocket server, or run some one-off command with it. e.g.,

docker run --rm phpswoole/swoole php -m
docker run --rm phpswoole/swoole php --ri swoole
docker run --rm phpswoole/swoole composer --version

We have various examples included under folder "examples/" to help developers better use the image. These examples are numerically ordered. Each example has a docker-compose.yml file included, along with some other files. To run an example, please start Docker containers using the docker-compose.yml file included, then check HTTP output from URL http://127.0.0.1 unless otherwise noted. You may use the following commands to start/stop/restart Docker containers:

./bin/example.sh start   00 # To start container(s) of the first example.
./bin/example.sh stop    00 # To stop container(s) of the first example.
./bin/example.sh restart 00 # To restart container(s) of the first example.

To run another example, just replace the last command line parameter 00 with an example number (e.g., 05).

Here is a list of the examples under folder "examples/":

Image Variants

The phpswoole/swoole images come in three flavors, each designed for a specific use case. In production environment, we suggest using the Alpine images.

1. latest, <swoole-version>, and <swoole-version>-php<php-version>

This variant is based on the php:cli images, with a few changes. It uses Supervisord to manage booting processes, and has Composer preinstalled.

2. latest-dev, <swoole-version>-dev, and <swoole-version>-php<php-version>-dev

This variant is very similar to the previous one, but it has extra tools added for testing, debugging, and monitoring purpose, including gdb, git, lsof, strace, tcpdump, Valgrind, and vim.

3. latest-alpine, <swoole-version>-alpine, and <swoole-version>-php<php-version>-alpine

You can use this variant in the same way as using the php:alpine image, except that we changed the default working directory to /var/www. Also, we have Composer preinstalled in the image.

Note: We don't have development tools built in for Alpine images. There is no Docker images like phpswoole/swoole:5.1.5-php8.2-alpine-dev.

Supported Tags and Respective Dockerfile Links

Versioned images (based on stable releases of Swoole)

Swoole 6.0

PHP VersionsDefault ImagesDev ImagesAlpine Images
PHP 8.36.0.0-beta-php8.3, 6.0-php8.36.0.0-beta-php8.3-dev, 6.0-php8.3-dev6.0.0-beta-php8.3-alpine, 6.0-php8.3-alpine
PHP 8.26.0.0-beta-php8.2, 6.0-php8.2,<br />6.06.0.0-beta-php8.2-dev, 6.0-php8.2-dev,<br />6.0-dev6.0.0-beta-php8.2-alpine, 6.0-php8.2-alpine,<br />6.0-alpine
PHP 8.16.0.0-beta-php8.1, 6.0-php8.16.0.0-beta-php8.1-dev, 6.0-php8.1-dev6.0.0-beta-php8.1-alpine, 6.0-php8.1-alpine

Swoole 5.1

PHP VersionsDefault ImagesDev ImagesAlpine Images
PHP 8.35.1.5-php8.3, 5.1-php8.35.1.5-php8.3-dev, 5.1-php8.3-dev5.1.5-php8.3-alpine, 5.1-php8.3-alpine
PHP 8.25.1.5-php8.2, 5.1-php8.2,<br />5.1, latest5.1.5-php8.2-dev, 5.1-php8.2-dev,<br />5.1-dev, latest-dev5.1.5-php8.2-alpine, 5.1-php8.2-alpine,<br />5.1-alpine, latest-alpine
PHP 8.15.1.5-php8.1, 5.1-php8.15.1.5-php8.1-dev, 5.1-php8.1-dev5.1.5-php8.1-alpine, 5.1-php8.1-alpine
PHP 8.05.1.5-php8.0, 5.1-php8.05.1.5-php8.0-dev, 5.1-php8.0-dev5.1.5-php8.0-alpine, 5.1-php8.0-alpine

Swoole 5.0

PHP VersionsDefault ImagesDev ImagesAlpine Images
PHP 8.25.0.3-php8.2, 5.0-php8.25.0.3-php8.2-dev, 5.0-php8.2-dev5.0.3-php8.2-alpine, 5.0-php8.2-alpine
PHP 8.15.0.3-php8.1, 5.0-php8.1,<br />5.05.0.3-php8.1-dev, 5.0-php8.1-dev,<br />5.0-dev5.0.3-php8.1-alpine, 5.0-php8.1-alpine,<br />5.0-alpine
PHP 8.05.0.3-php8.0, 5.0-php8.05.0.3-php8.0-dev, 5.0-php8.0-dev5.0.3-php8.0-alpine, 5.0-php8.0-alpine

Swoole 4.8

PHP VersionsDefault ImagesDev ImagesAlpine Images
PHP 8.24.8.13-php8.2, 4.8-php8.24.8.13-php8.2-dev, 4.8-php8.2-dev4.8.13-php8.2-alpine, 4.8-php8.2-alpine
PHP 8.14.8.13-php8.1, 4.8-php8.14.8.13-php8.1-dev, 4.8-php8.1-dev4.8.13-php8.1-alpine, 4.8-php8.1-alpine
PHP 8.04.8.13-php8.0, 4.8-php8.0,<br />4.84.8.13-php8.0-dev, 4.8-php8.0-dev,<br />4.8-dev4.8.13-php8.0-alpine, 4.8-php8.0-alpine,<br />4.8-alpine
PHP 7.44.8.13-php7.4, 4.8-php7.44.8.13-php7.4-dev, 4.8-php7.4-dev4.8.13-php7.4-alpine, 4.8-php7.4-alpine
PHP 7.34.8.13-php7.3, 4.8-php7.34.8.13-php7.3-dev, 4.8-php7.3-dev4.8.13-php7.3-alpine, 4.8-php7.3-alpine
PHP 7.24.8.13-php7.2, 4.8-php7.24.8.13-php7.2-dev, 4.8-php7.2-dev4.8.13-php7.2-alpine, 4.8-php7.2-alpine

Swoole 4.7

PHP VersionsDefault ImagesDev ImagesAlpine Images
PHP 8.04.7.1-php8.0, 4.7-php8.0,<br />4.74.7.1-php8.0-dev, 4.7-php8.0-dev,<br />4.7-dev4.7.1-php8.0-alpine, 4.7-php8.0-alpine,<br />4.7-alpine
PHP 7.44.7.1-php7.4, 4.7-php7.44.7.1-php7.4-dev, 4.7-php7.4-dev4.7.1-php7.4-alpine, 4.7-php7.4-alpine
PHP 7.34.7.1-php7.3, 4.7-php7.34.7.1-php7.3-dev, 4.7-php7.3-dev4.7.1-php7.3-alpine, 4.7-php7.3-alpine
PHP 7.24.7.1-php7.2, 4.7-php7.24.7.1-php7.2-dev, 4.7-php7.2-dev4.7.1-php7.2-alpine, 4.7-php7.2-alpine

Swoole 4.6

PHP VersionsDefault ImagesDev ImagesAlpine Images
PHP 8.04.6.7-php8.0, 4.6-php8.0,<br />4.64.6.7-php8.0-dev, 4.6-php8.0-dev,<br />4.6-dev4.6.7-php8.0-alpine, 4.6-php8.0-alpine,<br />4.6-alpine
PHP 7.44.6.7-php7.4, 4.6-php7.44.6.7-php7.4-dev, 4.6-php7.4-dev4.6.7-php7.4-alpine, 4.6-php7.4-alpine
PHP 7.34.6.7-php7.3, 4.6-php7.34.6.7-php7.3-dev, 4.6-php7.3-dev4.6.7-php7.3-alpine, 4.6-php7.3-alpine
PHP 7.24.6.7-php7.2, 4.6-php7.24.6.7-php7.2-dev, 4.6-php7.2-dev4.6.7-php7.2-alpine, 4.6-php7.2-alpine

Swoole 4.5

PHP VersionsDefault ImagesDev ImagesAlpine Images
PHP 8.04.5.11-php8.0, 4.5-php8.0,<br />4.54.5.11-php8.0-dev, 4.5-php8.0-dev,<br />4.5-dev4.5.11-php8.0-alpine, 4.5-php8.0-alpine,<br />4.5-alpine
PHP 7.44.5.11-php7.4, 4.5-php7.44.5.11-php7.4-dev, 4.5-php7.4-dev4.5.11-php7.4-alpine, 4.5-php7.4-alpine
PHP 7.34.5.11-php7.3, 4.5-php7.34.5.11-php7.3-dev, 4.5-php7.3-dev4.5.11-php7.3-alpine, 4.5-php7.3-alpine
PHP 7.24.5.11-php7.2, 4.5-php7.24.5.11-php7.2-dev, 4.5-php7.2-dev4.5.11-php7.2-alpine, 4.5-php7.2-alpine
PHP 7.14.5.11-php7.1, 4.5-php7.14.5.11-php7.1-dev, 4.5-php7.1-dev4.5.11-php7.1-alpine, 4.5-php7.1-alpine

Swoole 4.4

PHP VersionsDefault ImagesDev ImagesAlpine Images
PHP 7.44.4.25-php7.4, 4.4-php7.4,<br />4.44.4.25-php7.4-dev, 4.4-php7.4-dev,<br />4.4-dev4.4.25-php7.4-alpine, 4.4-php7.4-alpine,<br />4.4-alpine
PHP 7.34.4.25-php7.3, 4.4-php7.34.4.25-php7.3-dev, 4.4-php7.3-dev4.4.25-php7.3-alpine, 4.4-php7.3-alpine
PHP 7.24.4.25-php7.2, 4.4-php7.24.4.25-php7.2-dev, 4.4-php7.2-dev4.4.25-php7.2-alpine, 4.4-php7.2-alpine
PHP 7.14.4.25-php7.1, 4.4-php7.14.4.25-php7.1-dev, 4.4-php7.1-dev4.4.25-php7.1-alpine, 4.4-php7.1-alpine

Nightly images (built daily using the master branch of swoole-src)

PHP VersionsDefault ImagesDev ImagesAlpine Images
PHP 8.3php8.3php8.3-devphp8.3-alpine
PHP 8.2php8.2php8.2-devphp8.2-alpine
PHP 8.1php8.1php8.1-devphp8.1-alpine

Build Images Manually

The Docker images are built and pushed out automatically through Travis. If you want to build some image manually, please follow these three steps.

1. Install Composer packages. If you have command "composer" installed already, just run composer update -n.

2. Use commands like following to create dockerfiles:

./bin/generate-dockerfiles.php nightly # Generate dockerfiles to build images from the master branch of Swoole.
./bin/generate-dockerfiles.php 5.1.5   # Generate dockerfiles to build images for Swoole 5.1.5.

3. Build Docker images with commands like:

docker build -t phpswoole/swoole:php8.2              -f dockerfiles/nightly/php8.2/cli/Dockerfile   .
docker build -t phpswoole/swoole:5.1.5-php8.2        -f dockerfiles/5.1.5/php8.2/cli/Dockerfile    .
docker build -t phpswoole/swoole:5.1.5-php8.2-alpine -f dockerfiles/5.1.5/php8.2/alpine/Dockerfile .

To build development images (where extra tools are included), add an argument DEV_MODE:

docker build --build-arg DEV_MODE=true -t phpswoole/swoole:php8.2-dev       -f dockerfiles/nightly/php8.2/cli/Dockerfile .
docker build --build-arg DEV_MODE=true -t phpswoole/swoole:5.1.5-php8.2-dev -f dockerfiles/5.1.5/php8.2/cli/Dockerfile  .

Credits