Skip to content
🏄 Official Docker Image of Swoole
Dockerfile Shell PHP HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin more updates to build ARM images from Docker Hub Jan 20, 2020
config upgrade Composer from 1.9.1 to 1.9.2 Jan 17, 2020
dockerfiles remove PHP source code Jan 23, 2020
examples remove outdated script and update example Jan 17, 2020
hooks
rootfilesystem move qemu files Jan 20, 2020
src more updates to build ARM images from Docker Hub Jan 20, 2020
temp start adding new files for creating new official Docker images Aug 4, 2019
tests update version numbers Aug 26, 2019
.gitignore updates to build dev/non-dev images through separate builds in Docker… Jan 22, 2020
.travis.yml update CI tasks Jan 20, 2020
CHANGELOG.md add new example about Sdebug Jan 7, 2020
Dockerfile.twig remove PHP source code Jan 23, 2020
LICENSE add license and badge info Aug 24, 2019
README.md build dev/non-dev images through separate builds in Docker Hub to avo… Jan 21, 2020
composer.json to build ARM images from Docker Hub Jan 20, 2020
config.yml support PHP 7.4; exclude Swoole extensions and PHPX by default Jan 6, 2020
phpunit.xml.dist start adding new files for creating new official Docker images Aug 4, 2019

README.md

Docker Image for Swoole

Build Status 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.

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:

  • phpswoole/swoole:4.4.15-php7.1
  • phpswoole/swoole:4.4.15-php7.2
  • phpswoole/swoole:4.4.15-php7.3
  • phpswoole/swoole:4.4.15-php7.4
  • phpswoole/swoole:4.4.15-php7.1-arm64v8
  • phpswoole/swoole:4.4.15-php7.2-arm64v8
  • phpswoole/swoole:4.4.15-php7.3-arm64v8
  • phpswoole/swoole:4.4.15-php7.4-arm64v8

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.,

  • phpswoole/swoole:latest-dev
  • phpswoole/swoole:latest-arm64v8-dev
  • phpswoole/swoole:4.4.15-php7.1-dev
  • phpswoole/swoole:4.4.15-php7.4-arm64v8-dev

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.

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.
  • 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.

Examples

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).
  • 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-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 .

TODOs

  • Allow to stop the container gracefully.
  • Support more architectures.
  • Add Alpine image if needed.

Credits

Current implementation borrows ideas from Demin's work at Glu Mobile.

You can’t perform that action at this time.