• Stars
    star
    100
  • Rank 340,703 (Top 7 %)
  • Language
    Dockerfile
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 5 years ago

Reviews

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

Repository Details

A micro PHP Docker environment based on an Alpine image. Can be used for container publishing, the completed image is only 30-40M

Alpine PHP Docker

Docker Build Status Docker Pulls MicroBadger Layers (tag) MicroBadger Size (tag)

alphp - 基于alpine的微型php docker环境,php 是 7.x, 包含最新版本swoole。 构建完成的镜像只有30-40M,可以直接用于生产环境作镜像发布。

共有几个镜像

  • swoft/alphp:base 基础镜像,后几个镜像基于它(含有php和一些通用的扩展)
  • swoft/alphp:cli php cli环境镜像,含有最新版本 swoole 和 mongodb 扩展
  • swoft/alphp:fpm 基于 swoft/alphp:cli,含有 nginx php-fpm 组件
  • swoft/alphp:dev 基于 swoft/alphp:cli,含有 nginx php-fpm 以及一些常用工具:vim wget git zip telnet ab 等,可用于开发。

共有几个分支

  • master: 基于 alpine:3.8 镜像, php7.2
  • alpine-edge: 基于 alpine:edge 镜像, php7.2
  • alpine-3.7: 基于 alpine:3.7 镜像, php7.1

Dockerfile links

base on alpine 3.8(php 7.2.x):


直接拉取

docker pull swoft/alphp:base
docker pull swoft/alphp:cli
docker pull swoft/alphp:fpm
docker pull swoft/alphp:dev

hub.docker 地址: https://hub.docker.com/r/swoft/alphp/

本地构建

构建基础镜像

docker build . -f alphp-base.Dockerfile -t swoft/alphp:base

构建功能镜像

  • 构建 swoft/alphp:cli
docker build . -f alphp-cli.Dockerfile -t swoft/alphp:cli
  • 构建 swoft/alphp:fpm
// 在swoft/alphp:cli 的基础上,含有 nginx php-fpm
docker build . -f alphp-fpm.Dockerfile -t swoft/alphp:fpm
  • 构建 swoft/alphp:dev
// 在 swoft/alphp:cli 的基础上,含有 nginx php-fpm 额外包含一些常用工具:vim wget git zip telnet ab 等
docker build . -f alphp-dev.Dockerfile -t swoft/alphp:dev

一些有用的

更改软件源

sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/' /etc/apk/repositories

Dockerfile注意

  • 如果想要主进程接收 docker stop 信号(SIGTERM),一定要用 ENTRYPOINT 或者 RUN 来启动运行主进程,不能使用 CMD。

CMD 会始终使用 sh -c command 来执行命令,这样PID = 1 的就不是真实命令所在进程了

ENTRYPOINT ["php", "/var/www/bin/cli", "taskServer:restart"]

镜像中的一些信息

  • php execute file: /usr/bin/php
  • php ini file: /etc/php7/php.ini
  • 扩展配置目录:/etc/php7/conf.d
  • 扩展编译目录:/usr/lib/php7/modules
  • php-fpm execute file: /usr/bin/php-fpm
  • php-fpm conf: /etc/php7/php-fpm.conf

重新生成 composer autoload

composer up nothing

工具推荐

工具列表

  • composer 包管理
  • phpunit 单元测试
  • phpmd 代码检查
  • 类参考文档生成
  • deployer 一个用PHP编写的部署工具支持流行的框架
  • xhprof 安装

add composer

ADD tools/composer.phar /usr/local/bin/composer
RUN chmod 755 /usr/local/bin/composer

类参考文档生成

  • 使用 sami(推荐)
$ ./vendor/bin/sami.phar -V

生成:

$ php ./vendor/bin/sami.phar update build/sami.conf.php

分开执行:

// The parse command parses a project and generates a database
$ php ./vendor/bin/sami.phar parse config/symfony.php

// The render command renders a project as a static set of HTML files
$ php ./vendor/bin/sami.phar render config/symfony.php
  • 使用 apigen
$ ./vendor/bin/apigen.phar -V
$ ./vendor/bin/apigen.phar generate --help
$ ./vendor/bin/apigen.phar generate -s {source code dir} -d {doc generate dir}
  • 使用phpDocumentor
$ ./vendor/bin/phpDocumentor.phar -V
phpDocumentor version v2.9.0
$ ./vendor/bin/phpDocumentor.phar run -d {source code dir} -t {doc generate dir}

手动管理 php-fpm

#关闭php-fpm
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`

#重启php-fpm
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`

端口检查 lsof

lsof :9051

ab 压力测试

安装

// ubuntu
apt-get install apache2-utils
// centos
yum install httpd-tools

安装 swoole

官网 swoole.com 安装相关扩展 redis, zip, mbstring, inotify, pdo_mysql

相关库

编译命令

# phpize
# ./configure --enable-swoole-debug --enable-async-redis --enable-openssl --enable-sockets --enable-coroutine --with-php-config=/usr/local/bin/php-config
# make clean
# make -j
# make install

更多选项说明

使用 ./configure -h 可以看到全部的选项

  • --enable-swoole-debug // 打开调试日志,开启此选项后swoole将打印各类细节的调试日志。生产环境不要启用。
  • --enable-sockets // 增加对sockets资源的支持,依赖sockets扩展
  • --enable-async-redis // 增加异步Redis客户端支持, 依赖hiredis库
  • --enable-openssl // 启用SSL支持,依赖openssl库
  • --enable-http2 // 增加对HTTP2的支持,依赖nghttp2库. 必须开启openssl
  • --enable-coroutine // 启用协程能力(swoole 4 已去除此选项)

相关库

License

MIT

More Repositories

1

swoft

🚀 PHP Microservice Full Coroutine Framework
PHP
5,582
star
2

swoft-component

📦 This is a repository of centralized management of all swoft core components
PHP
97
star
3

swoft-doc

📖 Swoft Framework Document(swoft.io)
HTML
96
star
4

swoft-framework

[READ ONLY] Swoft Framework, base of Swoft
PHP
66
star
5

awesome-swoft

A curated list of bookmarks, packages, tutorials, videos and other cool resources from the Swoft ecosystem
49
star
6

swoft-cli

🛠️ Command line tool for quick use swoft. Support create new application, generate class, hot reload server and more.
PHP
47
star
7

swoole-ide-helper

💪 IDE helper for Swoft and Swoole
PHP
42
star
8

swoft-devtool

🛠️ Dev tool for Swoft [READ ONLY]
PHP
29
star
9

swoft-db

[READ ONLY] Database Compoment for Swoft
PHP
26
star
10

swoft-ext

🗂 Swoft extension components: amqp, apollo, breaker, consul, elasticsearch, grpc, kafka, limiter, view, zipkin
PHP
22
star
11

swoft-docker

Docker PHP development environment for swoft
Dockerfile
21
star
12

swoft-websocket-server

[READ ONLY] WebSocket Server for Swoft
PHP
17
star
13

swoft-design

swoft framework design
14
star
14

swoft-redis

[READ ONLY] Redis Compoment for Swoft
PHP
13
star
15

swoft-www-cn

Swoft chinese documents
HTML
12
star
16

swoft-http-client

HTTP Client Compoment for Swoft 1.x
PHP
12
star
17

swoft-auth

🔐 Auth compoment for Swoft
PHP
12
star
18

swoft-http-server

[READ ONLY] Swoft Http Server base on Swoole
PHP
12
star
19

swoft-rpc-server

[READ ONLY] RPC Server for Swoft
PHP
11
star
20

swoft-stdlib

[READ ONLY] PHP std tool class, helper class: string, array, object, json, env, php and more
PHP
10
star
21

swoft-amqp

Swoft amqp component
PHP
9
star
22

swoft-session

[READ ONLY] Http Session Compoment for Swoft
PHP
9
star
23

swoft-console

[READ ONLY] Console Compoment for Swoft
PHP
8
star
24

swoft-elasticsearch

Swoft elasticsearch component
PHP
8
star
25

swoft-http-message

[READ ONLY] HTTP Message Compoment for Swoft
PHP
8
star
26

swoft-cache

Cache Compoment for Swoft
PHP
7
star
27

swoft-rpc

[READ ONLY] RPC Compoment for Swoft
PHP
7
star
28

swoft-annotation

[READ ONLY] Swoft annotation component
PHP
6
star
29

swoft-memory

Memory Component for Swoft
PHP
6
star
30

swoft-apollo

[READ ONLY] Swoft Apollo Component
PHP
6
star
31

swoft-skeleton

Swoft skeleton project, intended to create bran-new appliacations fast
PHP
6
star
32

swoft-rpc-client

[READ ONLY] RPC Client Compoment for Swoft
PHP
6
star
33

swoft-swagger

[DEVELOPING] Swagger Compoment for Swoft
PHP
6
star
34

swoft-server

[READ ONLY] Swoft Server Component
PHP
6
star
35

swoft-event

[READ ONLY] Swoft event component
PHP
5
star
36

swoft-view

[READ ONLY] View Compoment for Swoft
PHP
5
star
37

swoft-tcp-server

[READ ONLY] Swoft TCP Server Component
PHP
5
star
38

swoft-whoops

[READ ONLY] Swoft errors for cool kids by filp/whoops
PHP
5
star
39

swoft-swoole-tracker

[READ ONLY] Enable Swoole Tracker On Swoft
PHP
5
star
40

swoft-connection-pool

[READ ONLY] Swoft Connection Pool Component
PHP
5
star
41

swoft-task

[READ ONLY] Task Compoment for Swoft
PHP
5
star
42

swoft-tcp

[READ ONLY] Swoft Tcp Protocol Component
PHP
4
star
43

swoft-consul

[READ ONLY] Swoft Consul Component
PHP
4
star
44

swoft-elasticsearch-client

No-blocking Coroutine Elasticsearch Client
4
star
45

swoft-trace

[DEVELOPING] Trace Component for Swoft
PHP
4
star
46

swoft-queue

[DEVELOPING] Queue Component for Swoft
4
star
47

swoft-http-project

Swoft http application demo project
PHP
4
star
48

swoft-process

[READ ONLY] Process Compoment for Swoft
PHP
4
star
49

swoft-service-governance

Service Governance for Swoft 1.0
PHP
4
star
50

swoft-case

👏 Swoft Project Case Collection
4
star
51

swoft-i18n

[READ ONLY] I18n Translations Component for Swoft
PHP
4
star
52

swoft-tcp-project

Swoft tcp demo project
4
star
53

swoft-crontab

[READ ONLY] Swoft Crontab Component
PHP
3
star
54

swoft-grpc

[PLAN] Swoft grpc component
3
star
55

swoft-limiter

[READ ONLY] Swoft Limiter Component
PHP
3
star
56

swoft-swlib

Wrap some swoole util class
PHP
3
star
57

swoft-breaker

[READ ONLY] Swoft Circuit Breaker
PHP
3
star
58

swoft-kafka

[PLAN] Swoft kafka Component
3
star
59

swoft-validator

[READ ONLY] Swoft validator component
PHP
3
star
60

swoft-testlib

PHP
3
star
61

swoft-websocket-project

Swoft websocket demo project
PHP
3
star
62

swoft-error

[READ ONLY] Error Handler Component of Swoft
PHP
3
star
63

swoft-config

[READ ONLY] Swoft config component
PHP
3
star
64

swoft-serialize

Data serializer for PHP
PHP
3
star
65

swoft-bean

[READ ONLY] Swoft bean container
PHP
2
star
66

forum

Swoft Official Forum. Swoft 官方论坛
2
star
67

swoft-zipkin

[DEVELOPING] Swoft Zipkin Component
2
star
68

swoft-aop

[READ ONLY] Swoft aop component
PHP
2
star
69

swoft-log

[READ ONLY] Swoft log component
PHP
2
star
70

swoft-socketio

[Work in progress]
PHP
2
star
71

swoft-defer

Swoole has been added `defer()` function after v4.2.9, so this project will be archived.
PHP
2
star
72

swoft-www

Swoft www
HTML
2
star
73

swoft-proxy

[READ ONLY] Swoft proxy
PHP
2
star
74

swoft-data-parser

Data parser of swoft 1.0(Now 2.0, please use swoft/swoft-serialize)
PHP
2
star
75

docker

Some docker files for build php images
Dockerfile
1
star