- Notifications
You must be signed in to change notification settings - Fork113
🏄 Official Docker Image of Swoole
License
swoole/docker-swoole
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This image is built for general-purpose. We have different examples included in this Git repository to help developersto get familiar with the image andSwoole.
You can get the image fromhere.
- Feature List
- How to Use This Image
- Image Variants
- Supported Tags and Respective Dockerfile Links
- Build Images Manually
- Credits
- Built-in scripts to manageSwoole extensions andSupervisord 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
COPYcommand 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 extensionpdo_mysql included since 4.8.12+ and 5.0.1+.2
- PHP extensionRedis included since 4.8.12+ and 5.0.1+.2 It's installed with default options.
NOTES
- The auto-reloading feature is supported for non-Alpine images only.
- To disable extensionpdo_mysql and/orRedis, please check sectionDisable Installed/Enabled PHP Extensions.
Thephpswoole/swoole image is built usingthe official PHP image as base image, with a few changes.For basic usage, please check the description section ofthe official PHP image.
Same as in the official PHP image, most PHP extensions can be installed/configured using built-in helper scriptsdocker-php-ext-configure,docker-php-ext-install,docker-php-ext-enable, anddocker-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-alpineRUN 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-alpineRUN 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-alpineRUN 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*
Since 4.8.12+ and 5.0.1+, PHP extensionspdo_mysql andRedis are installed and enabled by default. If you want todisable them, you can use the following commands in your Dockerfile.
FROM phpswoole/swoole:4.8-alpineRUN 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.
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 -mdocker run --rm phpswoole/swoole php --ri swooledocker run --rm phpswoole/swoole composer --version
We have various examples included under folder "examples/" to help developers better use the image. These examples arenumerically ordered. Each example has adocker-compose.yml file included, along with some other files. To run anexample, please start Docker containers using thedocker-compose.yml file included, then check HTTP output from URLhttp://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 parameter00 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 scriptupdate-token.sh.
- 07-disable-default-server: Please check thedocker-compose.yml file included to see show how to disable the default web server created withSwoole.
- 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 theREADME file included to see how to install Swoole extensions likeasync,orm,postgresql, andserialize.
- 14-install-phpx: Please check theREADME file included to see how to installPHP-X.
- 15-install-phpx-extension: Please check theREADME file included to see how to installPHP-X based extensions likezookeeper.
- 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 theREADME 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).
- 24-supervisord-gracefully-shutdown: how to gracefully stop Swoole servers (managed by
supervisord) in Docker containers.
- Debugging:
- 30-debug-with-gdb: Please check theREADME file included to see how to debug your PHP code withgdb.
- 31-debug-with-valgrind: Please check theREADME file included to see how to debug your PHP code withValgrind.
- 32-debug-with-strace: Please check theREADME file included to see how to debug your PHP code withstrace.
- 33-debug-with-blackfire: Please check theREADME file included to see how to debug your PHP code withBlackfire.
- 34-debug-with-xdebug: Please check theREADME file included to see how to debug your PHP code usingXdebug. 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.
Thephpswoole/swoole images come in three flavors, each designed for a specific use case.
phpswoole/swoole:latestphpswoole/swoole:5.1phpswoole/swoole:5.1-php8.2phpswoole/swoole:5.1.8-php8.2
This variant is based on thephp:cli images, with a few changes. It usesSupervisord to manage booting processes, and hasComposer preinstalled.
Since Swoole 6.0.0, there is a Zend Thread Safety (ZTS) version of the image available, which is suffixed with-zts. e.g.,phpswoole/swoole:6.0-php8.3-zts.
phpswoole/swoole:latest-devphpswoole/swoole:5.1-devphpswoole/swoole:5.1-php8.2-devphpswoole/swoole:5.1.8-php8.2-dev
This variant is very similar to the previous one, but it has extra tools added for testing, debugging, and monitoring purpose,includinggdb, git, lsof,strace,tcpdump,Valgrind, and vim.
Since Swoole 6.0.0, there is a Zend Thread Safety (ZTS) version of the image available, which is suffixed with-zts-dev. e.g.,phpswoole/swoole:6.0-php8.3-zts-dev.
phpswoole/swoole:latest-alpinephpswoole/swoole:5.1-alpinephpswoole/swoole:5.1-php8.2-alpinephpswoole/swoole:5.1.8-php8.2-alpine
You can use this variant in the same way as using thephp:alpine image, except that we changed the default working directory to/var/www.Also, we haveComposer preinstalled in the image.
Note: We don't have development tools built in for Alpine images. There is no Docker images likephpswoole/swoole:5.1.8-php8.2-alpine-dev.
| 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 | 5.0.3-php8.1-dev 5.0-php8.1-dev 5.0-dev | 5.0.3-php8.1-alpine 5.0-php8.1-alpine 5.0-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 |
| 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 |
Nightly images (built daily using the master branch ofswoole-src)
| PHP Versions | Default Images | Dev Images | ZTS Images | Alpine Images |
|---|---|---|---|---|
| PHP 8.4 | php8.4 | php8.4-dev | php8.4-zts | php8.4-alpine |
| PHP 8.3 | php8.3 | php8.3-dev | php8.3-zts | php8.3-alpine |
| PHP 8.2 | php8.2 | php8.2-dev | php8.2-zts | php8.2-alpine |
| PHP 8.1 | php8.1 | php8.1-dev | php8.1-zts | php8.1-alpine |
The Docker images are built and pushed out automatically through Travis. If you want to build some image manually, pleasefollow these three steps.
1. Install Composer packages. If you have command "composer" installed already, just runcomposer 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.8# Generate dockerfiles to build images for Swoole 5.1.8.
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.8-php8.2 -f dockerfiles/5.1.8/php8.2/cli/Dockerfile.docker build -t phpswoole/swoole:5.1.8-php8.2-alpine -f dockerfiles/5.1.8/php8.2/alpine/Dockerfile.
To build development images (where extra tools are included), add an argumentDEV_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.8-php8.2-dev -f dockerfiles/5.1.8/php8.2/cli/Dockerfile.
- Current implementation borrows ideas fromDemin's work atGlu Mobile.
- Thanks toBlackfire for providing free open-source subscription for their awesome profiling tool.
About
🏄 Official Docker Image of Swoole
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.