您好,欢迎访问一九零五行业门户网

创建一个运行 PHP 、NGINX 和 Hip Hop VM(HHVM) 的 Docker 容器

作者:mike ebinum 译者:叶可强 对于 docker,我感到非常的兴奋。作为一个很早就进行 .net 开发的开发人员,我工作中不喜欢的事情之一就是在不同的环境中部署和测试。部署一个 web 应用程序的过程绝对是一个噩梦般的经历。即便之后我迁移到基于 unix 平台开
作者:mike ebinum译者:叶可强
对于 docker,我感到非常的兴奋。作为一个很早就进行 .net 开发的开发人员,我工作中不喜欢的事情之一就是在不同的环境中部署和测试。部署一个 web 应用程序的过程绝对是一个噩梦般的经历。即便之后我迁移到基于 unix 平台开发,并且使用开源的工具/语言,如 node 、 java 、 scala 、 php 等等,我发现同样的部署问题一次又一次的发生。
使用如 docker 这样的工具,你可以让开发环境的配置精确得如生产环境的镜像一样。部署好 web 应用程序的容器,所有东西都被配置,也就无需担心关于部署的那些麻烦事。
如果你是一个 docker 的新手,并且不是十分确定它是什么,以下文章会是一个完美的学习纲要。。
docker lightweight linux containers for consistent development and deploymentdocker: using linux containers to support portable application deployment作为一个懒惰的程序员,我的梦想成真了,做好一次然后就无后顾之忧(在一定程度上)。通过这篇文章,我将展示如何基于下列开发环境去创建并且运行一个 docker 容器。
centosnginx web serverphp with hip hop vm (hhvm)dockerfile准备开始,我们创建一个 dockerfile —— dockerfile 包含如何创建所需镜像的指令。
from centos:centos6maintainer mike ebinum, hello@seedtech.io
使用 cent os 6.x告知 docker 使用官方社区最新版本的 centos 6.x 可用镜像。
更新镜像安装所有最新版本的包更新,并且把 red hat epel 的仓库加入可用的仓库列表。
run yum update -y >/dev/null && yum install -y http://ftp.riken.jp/linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm && curl -l -o /etc/yum.repos.d/hop5.repo http://www.hop5.in/yum/el6/hop5.repo
安装包安装 supervisord —— 我们将使用这个配置和控制运行在容器中的进程 - 、 nginx 、 php 、一些 php 的开发包以及 facebook 的 hhvm 。
run yum install -y python-meld3 http://dl.fedoraproject.org/pub/epel/6/i386/supervisor-2.1-8.el6.noarch.rpmrun [yum, -y, install, nginx, php, php-mysql, php-devel, php-gd, php-pecl-memcache, php-pspell, php-snmp, php-xmlrpc, php-xml,hhvm]
配置 nginx 、 hhvm 和 supervisord为 nginx 创建目录,并且把 index.php 文件加入 nginx 来展现。
run mkdir -p /var/www/html && chmod a+r /var/www/html && echo > /var/www/html/index.php
下一组指令是:
为 hhvm 添加一个配置文件,然后重启我们的 hhvm 服务为 supervisord 添加一个配置文件,然后启动 nginx 和 hhvm add config.hdf /etc/hhvm/config.hdf run service hhvm restart add nginx.conf /etc/nginx/conf.d/default.conf add supervisord.conf /etc/supervisord.conf run chkconfig supervisord on && chkconfig nginx on
添加一个 shell 脚本 /run.sh ,在 docker 容器运行时启动。run.sh
#!/bin/bashset -e -x echo starting supervisor in foreground supervisord -n
add scripts/run.sh /run.sh run chmod a+x /run.sh expose 22 80 entrypoint [/run.sh]
构建容器,并且打 tag
docker build -t centos-nginx-php5-hhvm .
现在我们有一个全功能的容器,我们可以像下面这样运行:
docker run -d -p 80:80 centos-nginx-php5-hhvm
如果你已经有本地的服务已经在运行并且占用了 80 端口,你能很容易的的改变容器的对外端口。
docker registry 提供这个 docker 镜像的可用版本。
dockerfile完整的 dockerfile 如下
# docker-version 1.0.0from centos:centos6maintainer mike ebinum, hello@seedtech.io# install dependencies for hhvm# yum update -y >/dev/null && run yum install -y http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm && curl -l -o /etc/yum.repos.d/hop5.repo http://www.hop5.in/yum/el6/hop5.repo# install supervisorrun yum install -y python-meld3 http://dl.fedoraproject.org/pub/epel/6/i386/supervisor-2.1-8.el6.noarch.rpm#install nginx, php, mysql, hhvmrun [yum, -y, install, nginx, php, php-mysql, php-devel, php-gd, php-pecl-memcache, php-pspell, php-snmp, php-xmlrpc, php-xml,hhvm]# create folder for server and add index.php file to for nginxrun mkdir -p /var/www/html && chmod a+r /var/www/html && echo > /var/www/html/index.php#setup hhvm - add config for hhvmadd config.hdf /etc/hhvm/config.hdf run service hhvm restart# add nginx configadd nginx.conf /etc/nginx/conf.d/default.conf# add supervisord config with hhvm setupadd supervisord.conf /etc/supervisord.conf#set to start automatically - supervisord, nginx and mysqlrun chkconfig supervisord on && chkconfig nginx onadd scripts/run.sh /run.shrun chmod a+x /run.sh expose 22 80 #start supervisord (which will start hhvm), nginx entrypoint [/run.sh]
在这篇文章中提到的其他的可用文件在 github 上。
下一步?太棒了!我们现在有了一个环境配置,但我如何运行 php 应用程序?我将做后续的文章介绍如何使用这个容器来安装和配置 php 应用程序。欢迎订阅这个 博客,也可以在在 twitter 关注 @mikeebinum 和 @seedtechio 来获得更新。
这篇文章由 mike ebinum 撰写,叶可强 翻译。点击 这里 阅读原文。the article was contributed by mike ebinum, click here to read the original publication. 原文地址:创建一个运行 php 、nginx 和 hip hop vm(hhvm) 的 docker 容器, 感谢原作者分享。
其它类似信息

推荐信息