Dockerfile

准备开始,我们创建一个 Dockerfile —— Dockerfile 包含如何创建所需镜像的指令。

FROM    centos:centos6
MAINTAINER 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.rpm
RUN ["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 "<?php phpinfo(); ?>" > /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/bash
set -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.0
FROM    centos:centos6
MAINTAINER 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 supervisor
RUN yum install -y python-meld3 http://dl.fedoraproject.org/pub/epel/6/i386/supervisor-2.1-8.el6.noarch.rpm
#install nginx, php, mysql, hhvm
RUN ["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 nginx
RUN mkdir -p /var/www/html && chmod a+r /var/www/html && echo "<?php phpinfo(); ?>" > /var/www/html/index.php
#Setup hhvm - add config for hhvm
ADD config.hdf /etc/hhvm/config.hdf
RUN service hhvm restart
# ADD Nginx config
ADD nginx.conf /etc/nginx/conf.d/default.conf
# ADD supervisord config with hhvm setup
ADD supervisord.conf /etc/supervisord.conf
#set to start automatically - supervisord, nginx and mysql
RUN chkconfig supervisord on && chkconfig nginx on
ADD scripts/run.sh /run.sh
RUN chmod a+x /run.sh
EXPOSE 22 80
#Start supervisord (which will start hhvm), nginx
ENTRYPOINT ["/run.sh"]

docker下PHP+Nginx+HHVM运行环境的更多相关文章

  1. 在Docker下部署Nginx

    在Docker下部署Nginx 在Docker下部署Nginx,包括: 部署一个最简单的Nginx,可以通过80端口访问默认的网站 设置记录访问和错误日志的路径 设置静态网站的路径 通过proxy_p ...

  2. Centos7安装Docker 基于Dockerfile 搭建httpd运行环境

    Centos7安装Docker 基于Dockerfile 搭建httpd运行环境 docker docker搭建 docker build 本文档完成目标内容如下 使用Docker搭建http服务器一 ...

  3. windows下搭建nginx+php开发环境

    windows下搭建nginx+php开发环境 1.前言 windows下大多我们都是下载使用集成环境,但是本地已经存在一个集成环境,但不适合项目的需求.因此准备再自己搭建一个环境. 2.准备 工具: ...

  4. Ubuntu 下部署asp.net运行环境

    在Ubuntu下部署asp.net运行环境,网上教程很多,基本都是编译Mono源码,然后安装jexus.但是可能是我最近RP不太好,编译Mono源码一直都是失败,无奈之下只好找另外的方法安装了. 网上 ...

  5. SAAS云平台搭建札记: (二) Linux Ubutu下.Net Core整套运行环境的搭建

    最近做的项目,由于预算有限,公司决定不采购Windows服务器,而采购基于Linux的服务器. 一般的VPS服务器,如果使用Windows系统,那么Windows Server2012\2016安装好 ...

  6. Linux下用Docker部署接口安全的运行环境

    背景:MySQL数据库运行在宿主机上(Linux) 需求:Redis.服务.页面分别运行在独立的docker中,并处于同一网络,容器内部重要目录要挂载在物理目录,保证数据安全 方法: 一.设置网络环境 ...

  7. 用docker toolBox 搭建 nginx + flask + redis 环境

    本篇博客,主要是了解一下docker-compose的使用,docker-compose是官方给出的同时部署多个容器的解决方案:当你需要多个容器同时运行作为你的解决方案时:比如构建一个网站,需要php ...

  8. Docker + node(koa) + nginx + mysql 开发环境搭建

    什么是Docker Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源. Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然 ...

  9. docker之配置TensorFlow的运行环境

    Docker是一种 操作系统层面的虚拟化技术,类似于传统的虚拟机.传统虚拟机技术是虚拟出一套硬件后,在其上运行一个完整操作系统,在该系统上再运行所需应用进程:而容器内的应用进程直接运行于宿主的内核,容 ...

随机推荐

  1. sql 自定义函数-16进制转10进制

    做过笔记,好记性不如烂笔头: if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[HEXTOINT]') and ...

  2. jboss部署出现MarshalOutputStream找不到错误

    在jboss EAP 6.3上部署一个war时,项目使用oracle coherence做为缓存,出现如下错误 Caused by: java.lang.NoClassDefFoundError: s ...

  3. CF Polycarpus' Dice (数学)

    Polycarpus' Dice time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. JavaScript常用的经典小技巧

    1.屏蔽鼠标右键 <--body 方式--> <body oncontextmenu="window.event.returnValue=false"> & ...

  5. Git CMD - reset: Reset current HEAD to the specified state

    命令格式 git reset [-q] [<tree-ish>] [--] <paths>…​ git reset (--patch | -p) [<tree-ish&g ...

  6. sql查询统计,根据新闻类别ID统计,没有数据显示0

    有两张表,新闻信息表MessageInfo和新闻类别表MessageType.表结构如下: 然后需要实现下面这种查询结果: 这个是我面试时遇到的,上面的新闻类型是乱写的.当时没有做出来,然后回来又研究 ...

  7. 第四十三篇、利用NSProxy解决NSTimer内存泄漏问题

    问题描述: 用NSTimer来实现每隔一定时间执行制定的任务,例如最常见的广告轮播图.如果我们在 timerWithTimeInterval:1 target:self 中指定target为当前控制器 ...

  8. Objective-C 【动态类型检测&响应方法】

    ------------------------------------------- 动态类型检测 代码: #import <Foundation/Foundation.h> @inte ...

  9. 捕获异常 winform

    可以捕获winform中的异常写到文本中 <p>可以捕获winform中的异常写到文本中</p> <div class="cnblogs_code" ...

  10. jQuery中的getter和setter方法

    1.attr()方法是jQuery中用于HTML属性的getter/setter.一个相关函数是removeAttr(). 2.css()方法和attr()方法很类似,只是css()方法作用于元素的c ...