ronmi / dockerkit
此软件包的最新版本(0.1.7)没有可用的许可信息。
0.1.7
2016-03-04 03:41 UTC
Requires (Dev)
README
DockerKit 不是 Fruit 框架的一部分。
DockerKit 是一套工具,帮助您从 PHP 管理docker容器/镜像。
默认情况下,DockerKit 仅支持bash作为shell,不支持使用如zsh等其他shell。
摘要
编写您的dockerfile生成器
$f = new Fruit\DockerKit\Dockerfile('debian:latest', 'John Doe <john@example.com>'); $f ->distro('debian') ->install(['php5-fpm', 'php5']) ->ensureBash() ->grouping(true) ->textfileArray([ '#!/bin/bash', 'service php5-fpm restart', 'trap "echo Stopping fpm...;service php5-fpm stop" INT TERM', '(kill -STOP $BASHPID)&', 'wait', ], '/start.sh') ->chmod('a+x', '/start.sh') ->grouping(false) ->entrypoint(['bash', '/start.sh']); echo $f->generate();
它将生成
FROM debian:latest
MAINTAINER John Doe <john@example.com>
RUN apt-get update \
&& apt-get install -y php5-fpm php5 \
&& apt-get clean \
&& echo 'dash dash/sh boolean false'|debconf-set-selections \
&& DEBIAN_FRONTEND=noninteractive dpkg-reconfigure dash \
&& echo '#!/bin/bash'|tee /start.sh \
&& echo 'service php5-fpm restart'|tee -a /start.sh \
&& echo 'trap "echo Stopping fpm...;service php5-fpm stop" INT TERM'|tee -a /start.sh \
&& echo '(kill -STOP $BASHPID)&'|tee -a /start.sh \
&& echo 'wait'|tee -a /start.sh \
&& chmod a+x /start.sh
ENTRYPOINT ["bash","/start.sh"]
因此,您可以将其通过管道传递给 docker build
,例如 php my_generator.php|docker build -t my_tag -
,或者
(new Fruit\DockerKit\DockerBuild('my_tag')->run($f);
分组
分组可以将shell命令合并为一个 RUN
命令,减少构建镜像时所需的中间层。
安装程序
您可以为在不同的dockerfile生成器之间共享相同的应用程序/库编写自定义安装程序。例如,查看 src/ServiceStarter.php
,它可以帮助您生成管理服务启动/停止的shell脚本。
$f = new Fruit\DockerKit\Dockerfile('debian:latest', 'John Doe <john@example.com>'); $f->distro('debian')->install(['nginx', 'php5-fpm']); (new Fruit\DockerKit\ServiceStarter('/entry.sh')) ->starters([ 'service php5-fpm start', 'service nginx start', ]) ->stopers([ 'service php5-fpm stop', 'service nginx stop', ]) ->installTo($f); echo $f->entrypoint('/entry.sh')->generate();
将生成
FROM debian:latest
MAINTAINER John Doe <john@example.com>
RUN apt-get update \
&& apt-get install -y nginx php5-fpm \
&& apt-get clean \
&& echo '#!/bin/bash'|tee /entry.sh \
&& echo 'function start() {'|tee -a /entry.sh \
&& echo ' service php5-fpm start'|tee -a /entry.sh \
&& echo ' service nginx start'|tee -a /entry.sh \
&& echo '}'|tee -a /entry.sh \
&& echo ''|tee -a /entry.sh \
&& echo 'function stop() {'|tee -a /entry.sh \
&& echo ' service php5-fpm stop'|tee -a /entry.sh \
&& echo ' service nginx stop'|tee -a /entry.sh \
&& echo '}'|tee -a /entry.sh \
&& echo 'trap stop INT TERM'|tee -a /entry.sh \
&& echo ''|tee -a /entry.sh \
&& echo '(kill -SIGSTOP $BASHPID)&'|tee -a /entry.sh \
&& echo 'wait'|tee -a /entry.sh \
&& chmod a+x /entry.sh
ENTRYPOINT /entry.sh
支持的发行版
目前我们只支持Debian。欢迎提交PR。有关如何实现的信息,请参阅 src/Distro/Distro.php
。
更多示例
您可以在测试用例中找到更多示例,特别是这里未记录的命令。
许可
您可以选择GPL、LGPL或MIT许可。