Docker Image for Swoole
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.
List of Images
Image phpswoole/swoole is built using a recent commit from the master branch of the Swoole project.
Besides that, we build images with major versions of PHP (7.1 to 7.4) under different architectures (amd64 and arm64v8 only for now). For example, we have following images built for Swoole 4.4.15:
We also build development images where extra tools are included for testing, debugging, and monitoring purpose. Development images are tagged in the format of <image name>:<image tag>-dev (a "dev" postfix added to the original image tag). e.g.,
Here is the list of commands and tools available in development images:
PHP-X and Swoole extensions are not installed by default. Please check section "Examples" below to see how to install them manually.
- 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
COPYcommand only in dockerfiles).
- Composer included.
- Built for different architectures (for now only amd64 and arm64v8 images are built).
- Support auto-reloading for local development.
- Support code debugging for local development.
You may 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-autoload: 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).
- 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-sdebug: Please check the README file included to see how to debug your PHP code in different ways with sdebug (forked from Xdebug to work with Swoole).
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 latest # Generate dockerfiles to build images from the master branch of Swoole. ./bin/generate-dockerfiles.php 4.4.15 # Generate dockerfiles to build images for Swoole 4.4.15.
3. Build Docker images with commands like:
docker build -t phpswoole/swoole -f dockerfiles/latest/amd64/php7.4/Dockerfile . docker build -t phpswoole/swoole:latest-arm64v8 -f dockerfiles/latest/arm64v8/php7.4/Dockerfile . docker build -t phpswoole/swoole:4.4.15-php7.1 -f dockerfiles/4.4.15/amd64/php7.1/Dockerfile . docker build -t phpswoole/swoole:4.4.15-php7.4-arm64v8 -f dockerfiles/4.4.15/arm64v8/php7.4/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/amd64/php7.4/Dockerfile . docker build --build-arg DEV_MODE=true -t phpswoole/swoole:latest-arm64v8-dev -f dockerfiles/latest/arm64v8/php7.4/Dockerfile . docker build --build-arg DEV_MODE=true -t phpswoole/swoole:4.4.15-php7.1-dev -f dockerfiles/4.4.15/amd64/php7.1/Dockerfile . docker build --build-arg DEV_MODE=true -t phpswoole/swoole:4.4.15-php7.4-arm64v8-dev -f dockerfiles/4.4.15/arm64v8/php7.4/Dockerfile .
- Allow to stop the container gracefully.
- Support more architectures.
- Add Alpine image if needed.