• Stars
    star
    499
  • Rank 88,038 (Top 2 %)
  • Language
    Dockerfile
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ„ Official Docker Image of Swoole

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

  • Built-in scripts to manage Swoole extensions and Supervisord programs.
  • Easy to manage booting scripts in Docker.
  • Allow running PHP scripts and other commands directly in different environments (including ECS).
  • Use one root filesystem for simplicity (one Docker COPY command only in dockerfiles).
  • Composer included (Composer v1 for Swoole 4.5.8 and before; Composer v2 for Swoole 4.5.9 and after).
  • Built for different architectures.
  • Support auto-reloading for local development.1
  • Support code debugging for local development.
  • PHP extension pdo_mysql included since 4.8.12+ and 5.0.1+.2
  • PHP extension Redis included since 4.8.12+ and 5.0.1+.2 It's installed with default options.

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/":

  • Basic examples:
    • 00-autoreload: Restart the Swoole web server automatically if file changes detected under web root.
    • 01-basic: print out "Hello, World!" using Swoole as backend HTTP server.
    • 02-www: to use some customized PHP script(s) in the Docker image built.
    • 03-nginx: to use Swoole behind an Nginx server.
    • 04-entrypoint: to use a self-defined entrypoint script in the Docker image built.
    • 05-boot: to update content in the Docker container through a booting script.
    • 06-update-token: to show how to update server configurations with built-in script update-token.sh.
    • 07-disable-default-server: Please check the docker-compose.yml file included to see show how to disable the default web server created with Swoole.
  • Manage PHP extensions and configurations:
    • 10-install-php-extension: how to install/enable PHP extensions.
    • 11-customize-extension-options: how to overwrite/customize PHP extension options.
    • 12-php.ini: how to overwrite/customize PHP options.
    • 13-install-swoole-extension: Please check the README file included to see how to install Swoole extensions like async, orm, postgresql, and serialize.
    • 14-install-phpx: Please check the README file included to see how to install PHP-X.
    • 15-install-phpx-extension: Please check the README file included to see how to install PHP-X based extensions like zookeeper.
  • Manage Supervisord programs:
    • 20-supervisord-services: to show how to run Supervisord program(s) in Docker.
    • 21-supervisord-tasks: to show how to run Supervisord program(s) when launching a one-off command with Docker. Please check the README file included to see how to run the example.
    • 22-supervisord-enable-program: to show how to enable program(s) in Supervisord program.
    • 23-supervisord-disable-program: to show how to disable Supervisord program(s).
  • Debugging:
    • 30-debug-with-gdb: Please check the README file included to see how to debug your PHP code with gdb.
    • 31-debug-with-valgrind: Please check the README file included to see how to debug your PHP code with Valgrind.
    • 32-debug-with-strace: Please check the README file included to see how to debug your PHP code with strace.
    • 33-debug-with-blackfire: Please check the README file included to see how to debug your PHP code with Blackfire.
    • 34-debug-with-xdebug: Please check the README file included to see how to debug your PHP code using Xdebug. Please note that Xdebug 3.1.0+ works with Swoole 5.0.2+ on PHP 8.1+ only. Lower versions of Xdebug don't work with Swoole.

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>

  • phpswoole/swoole:latest
  • phpswoole/swoole:5.0
  • phpswoole/swoole:5.0-php8.1
  • phpswoole/swoole:5.0.3-php8.1

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

  • phpswoole/swoole:latest-dev
  • phpswoole/swoole:5.0-dev
  • phpswoole/swoole:5.0-php8.1-dev
  • phpswoole/swoole:5.0.3-php8.1-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

  • phpswoole/swoole:latest-alpine
  • phpswoole/swoole:5.0-alpine
  • phpswoole/swoole:5.0-php8.1-alpine
  • phpswoole/swoole:5.0.3-php8.1-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.0.3-php8.1-alpine-dev.

Supported Tags and Respective Dockerfile Links

Versioned images (based on stable releases of Swoole)

Swoole 5.0

PHP Versions Default Images Dev Images Alpine Images
PHP 8.2 5.0.3-php8.2, 5.0-php8.2 5.0.3-php8.2-dev, 5.0-php8.2-dev 5.0.3-php8.2-alpine, 5.0-php8.2-alpine
PHP 8.1 5.0.3-php8.1, 5.0-php8.1,
5.0, latest
5.0.3-php8.1-dev, 5.0-php8.1-dev,
5.0-dev, latest-dev
5.0.3-php8.1-alpine, 5.0-php8.1-alpine,
5.0-alpine, latest-alpine
PHP 8.0 5.0.3-php8.0, 5.0-php8.0 5.0.3-php8.0-dev, 5.0-php8.0-dev 5.0.3-php8.0-alpine, 5.0-php8.0-alpine

Swoole 4.8

PHP Versions Default Images Dev Images Alpine Images
PHP 8.2 4.8.13-php8.2, 4.8-php8.2 4.8.13-php8.2-dev, 4.8-php8.2-dev 4.8.13-php8.2-alpine, 4.8-php8.2-alpine
PHP 8.1 4.8.13-php8.1, 4.8-php8.1 4.8.13-php8.1-dev, 4.8-php8.1-dev 4.8.13-php8.1-alpine, 4.8-php8.1-alpine
PHP 8.0 4.8.13-php8.0, 4.8-php8.0,
4.8
4.8.13-php8.0-dev, 4.8-php8.0-dev,
4.8-dev
4.8.13-php8.0-alpine, 4.8-php8.0-alpine,
4.8-alpine
PHP 7.4 4.8.13-php7.4, 4.8-php7.4 4.8.13-php7.4-dev, 4.8-php7.4-dev 4.8.13-php7.4-alpine, 4.8-php7.4-alpine
PHP 7.3 4.8.13-php7.3, 4.8-php7.3 4.8.13-php7.3-dev, 4.8-php7.3-dev 4.8.13-php7.3-alpine, 4.8-php7.3-alpine
PHP 7.2 4.8.13-php7.2, 4.8-php7.2 4.8.13-php7.2-dev, 4.8-php7.2-dev 4.8.13-php7.2-alpine, 4.8-php7.2-alpine

Swoole 4.7

PHP Versions Default Images Dev Images Alpine Images
PHP 8.0 4.7.1-php8.0, 4.7-php8.0,
4.7
4.7.1-php8.0-dev, 4.7-php8.0-dev,
4.7-dev
4.7.1-php8.0-alpine, 4.7-php8.0-alpine,
4.7-alpine
PHP 7.4 4.7.1-php7.4, 4.7-php7.4 4.7.1-php7.4-dev, 4.7-php7.4-dev 4.7.1-php7.4-alpine, 4.7-php7.4-alpine
PHP 7.3 4.7.1-php7.3, 4.7-php7.3 4.7.1-php7.3-dev, 4.7-php7.3-dev 4.7.1-php7.3-alpine, 4.7-php7.3-alpine
PHP 7.2 4.7.1-php7.2, 4.7-php7.2 4.7.1-php7.2-dev, 4.7-php7.2-dev 4.7.1-php7.2-alpine, 4.7-php7.2-alpine

Swoole 4.6

PHP Versions Default Images Dev Images Alpine Images
PHP 8.0 4.6.7-php8.0, 4.6-php8.0,
4.6
4.6.7-php8.0-dev, 4.6-php8.0-dev,
4.6-dev
4.6.7-php8.0-alpine, 4.6-php8.0-alpine,
4.6-alpine
PHP 7.4 4.6.7-php7.4, 4.6-php7.4 4.6.7-php7.4-dev, 4.6-php7.4-dev 4.6.7-php7.4-alpine, 4.6-php7.4-alpine
PHP 7.3 4.6.7-php7.3, 4.6-php7.3 4.6.7-php7.3-dev, 4.6-php7.3-dev 4.6.7-php7.3-alpine, 4.6-php7.3-alpine
PHP 7.2 4.6.7-php7.2, 4.6-php7.2 4.6.7-php7.2-dev, 4.6-php7.2-dev 4.6.7-php7.2-alpine, 4.6-php7.2-alpine

Swoole 4.5

PHP Versions Default Images Dev Images Alpine Images
PHP 8.0 4.5.11-php8.0, 4.5-php8.0,
4.5
4.5.11-php8.0-dev, 4.5-php8.0-dev,
4.5-dev
4.5.11-php8.0-alpine, 4.5-php8.0-alpine,
4.5-alpine
PHP 7.4 4.5.11-php7.4, 4.5-php7.4 4.5.11-php7.4-dev, 4.5-php7.4-dev 4.5.11-php7.4-alpine, 4.5-php7.4-alpine
PHP 7.3 4.5.11-php7.3, 4.5-php7.3 4.5.11-php7.3-dev, 4.5-php7.3-dev 4.5.11-php7.3-alpine, 4.5-php7.3-alpine
PHP 7.2 4.5.11-php7.2, 4.5-php7.2 4.5.11-php7.2-dev, 4.5-php7.2-dev 4.5.11-php7.2-alpine, 4.5-php7.2-alpine
PHP 7.1 4.5.11-php7.1, 4.5-php7.1 4.5.11-php7.1-dev, 4.5-php7.1-dev 4.5.11-php7.1-alpine, 4.5-php7.1-alpine

Swoole 4.4

PHP Versions Default Images Dev Images Alpine Images
PHP 7.4 4.4.25-php7.4, 4.4-php7.4,
4.4
4.4.25-php7.4-dev, 4.4-php7.4-dev,
4.4-dev
4.4.25-php7.4-alpine, 4.4-php7.4-alpine,
4.4-alpine
PHP 7.3 4.4.25-php7.3, 4.4-php7.3 4.4.25-php7.3-dev, 4.4-php7.3-dev 4.4.25-php7.3-alpine, 4.4-php7.3-alpine
PHP 7.2 4.4.25-php7.2, 4.4-php7.2 4.4.25-php7.2-dev, 4.4-php7.2-dev 4.4.25-php7.2-alpine, 4.4-php7.2-alpine
PHP 7.1 4.4.25-php7.1, 4.4-php7.1 4.4.25-php7.1-dev, 4.4-php7.1-dev 4.4.25-php7.1-alpine, 4.4-php7.1-alpine

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

PHP Versions Default Images Dev Images Alpine Images
PHP 8.2 php8.2 php8.2-dev php8.2-alpine
PHP 8.1 php8.1 php8.1-dev php8.1-alpine
PHP 8.0 php8.0 php8.0-dev php8.0-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.0.3   # Generate dockerfiles to build images for Swoole 5.0.3.

3. Build Docker images with commands like:

docker build -t phpswoole/swoole                     -f dockerfiles/latest/php8.1/cli/Dockerfile   .
docker build -t phpswoole/swoole:5.0.3-php8.1        -f dockerfiles/5.0.3/php8.1/cli/Dockerfile    .
docker build -t phpswoole/swoole:5.0.3-php8.1-alpine -f dockerfiles/5.0.3/php8.1/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:latest-dev       -f dockerfiles/latest/php8.1/cli/Dockerfile .
docker build --build-arg DEV_MODE=true -t phpswoole/swoole:5.0.3-php8.1-dev -f dockerfiles/5.0.3/php8.1/cli/Dockerfile  .

Credits

  • Current implementation borrows ideas from Demin's work at Glu Mobile.
  • Thanks to Blackfire for providing free open-source subscription for their awesome profiling tool.

More Repositories

1

swoole-src

๐Ÿš€ Coroutine-based concurrency library for PHP
C++
18,406
star
2

phpx

๐Ÿ’— C++ wrapper for Zend API
C++
823
star
3

php-cp

pdo and redis tcp connect proxy
C
639
star
4

ide-helper

๐Ÿ“˜ Swoole IDE Helper
PHP
469
star
5

yasd

Yet Another Swoole Debugger
PHP
356
star
6

swoole-wiki

๐Ÿ“–Swooleๅ…จ้‡Markdownๆ–‡ๆกฃ, Swoole-Doc, Swoole-Wiki
Shell
270
star
7

phpkafka

PHP Kafka client is used in PHP-FPM and Swoole. PHP Kafka client supports 50 APIs, which might be one that supports the most message types ever.
PHP
266
star
8

awesome-swoole

๐Ÿ’Ž A curated list of awesome things related to Swoole.
230
star
9

library

๐Ÿ“š Swoole Library
PHP
221
star
10

grpc

๐Ÿ’Ž Grpc client based on Swoole Coroutine
PHP
199
star
11

ext-zookeeper

๐Ÿง‘ Coroutine-based ZooKeeper Client for PHP
C
150
star
12

swoole-cli

SWOOLE-CLI is a php binary distribution composed swoole & php-core & cli & fpm and mostly of common extensions.
C
119
star
13

community-chinese

Swoole ๆๆกˆ
117
star
14

thrift-rpc-server

Thrift RPC Server based on swoole
PHP
115
star
15

auto_reload

Inotify็›‘ๆŽงๆ–‡ไปถๅ˜ๆ›ด่‡ชๅŠจ้‡ๅฏswoole_server
PHP
105
star
16

ext-serialize

the fastest serialize function bound for php7
C
93
star
17

ext-async

Asynchronous callback client
PHP
87
star
18

proxy-server

Full asynchronous proxy server can support over a large number of concurrent.
PHP
84
star
19

debugger

Swoole ่ฟœ็จ‹่ฐƒ่ฏ•ๅ™จ
PHP
79
star
20

ext-postgresql

๐Ÿ˜ Coroutine-based client for PostgreSQL
C++
64
star
21

swoole-docs

๐Ÿ“— Please check the latest version: https://www.swoole.co.uk/docs/
61
star
22

phpy

PHP
43
star
23

zmq

ZeroMQ bindings for Swoole
PHP
37
star
24

dashboard

Vue
22
star
25

php-docker

php docker file
Dockerfile
20
star
26

docs

PHP
10
star
27

benchmark

PHP
9
star
28

make-library

Convert PHP code to C/C++ header file
PHP
6
star
29

documents

2
star
30

swoole.github.io

Swoole's website, docs & blog mainly focused on the english-speaking community.
CSS
2
star
31

v4.4-lts

C++
1
star
32

golang-h2demo

Go
1
star