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. Android(java)学习笔记94:关于广播接收者的注册和使用心得

    下面我们先看一部分代码,由代码进行进一步的深入: registerReceiver( new BroadcastReceiver() {//onReceive中代码的执行时间不要超过5s,androi ...

  2. ibatis中isEquals、isNotEmpty的用法

    一:isEquals用于动态拼接sql 如下实例: 如果status的状态为0,则更新attribute1;状态为1,则更新attribute2; 状态为2,则更新attribute3. <up ...

  3. nmap命令-----基础用法

    系统漏洞扫描之王-nmap   NMap,也就是Network Mapper,是Linux下的网络扫描和嗅探工具包.   其基本功能有三个: (1)是扫描主机端口,嗅探所提供的网络服务 (2)是探测一 ...

  4. Jersey(1.19.1) - Security

    Security information is available by obtaining the SecurityContext using @Context, which is essentia ...

  5. 第六节 ADO.NET

    ADO.NET是一组为.NET编程人员提供数据访问服务的类,封装在System.Data.dll 中,是.NET框架的一部分,它是一种数据访问技术. 使用SQLServer数据提供程序 类 说明 Sq ...

  6. CSS之导航菜单

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. Android之帧动画

    MySurfaceView类: package com.fm; import android.content.Context; import android.graphics.Bitmap; impo ...

  8. Linux c字符串中不可打印字符转换成16进制

    本文由 www.169it.com 搜集整理 如果一个C字符串中同时包含可打印和不可打印的字符,如果想将这个字符串写入文件,同时方便打开文件查看或者在控制台中打印出来不会出现乱码,那么可以将字符串中的 ...

  9. RNN-theano代码解析

    import theano import numpy import os import pdb from theano import tensor as T from collections impo ...

  10. 配置tomcat免安装版服务器

    一.首先,确保服务器已经安装java环境,没有tomcat的可以到这里下载 http://tomcat.apache.org/ 二.解压下载的压缩包,我是解压到D盘根目录下的.记住这个目录,后面会用到 ...