Git Product home page Git Product logo

docker-swoole's Introduction

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.

Supported Tags and Respective Dockerfile Links

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.18:

  • phpswoole/swoole:4.4.18-php7.1
  • phpswoole/swoole:4.4.18-php7.2
  • phpswoole/swoole:4.4.18-php7.3
  • phpswoole/swoole:4.4.18-php7.4
  • phpswoole/swoole:4.4.18-php7.1-arm64v8
  • phpswoole/swoole:4.4.18-php7.2-arm64v8
  • phpswoole/swoole:4.4.18-php7.3-arm64v8
  • phpswoole/swoole:4.4.18-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.18-php7.1-dev
  • phpswoole/swoole:4.4.18-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.18 # Generate dockerfiles to build images for Swoole 4.4.18.

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.18-php7.1         -f dockerfiles/4.4.18/amd64/php7.1/Dockerfile   .
docker build -t phpswoole/swoole:4.4.18-php7.4-arm64v8 -f dockerfiles/4.4.18/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.18-php7.1-dev         -f dockerfiles/4.4.18/amd64/php7.1/Dockerfile   .
docker build --build-arg DEV_MODE=true -t phpswoole/swoole:4.4.18-php7.4-arm64v8-dev -f dockerfiles/4.4.18/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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.