Create a Docker container running PHP, NGINX, and HipHopVM (HHVM)

Source: Internet
Author: User
Tags hhvm docker registry
I am very excited about Docker by MikeEbinum Translator: ye Keqiang. As a developer who has been developing. NET for a long time, one of the things I don't like at work is to deploy and test in different environments. Deploying a web application is definitely a nightmare. Even if I migrate to a UNIX-based platform later

Author: Mike Ebinum Translator: ye Keqiang is very excited about Docker. As a developer who has been developing. NET for a long time, one of the things I don't like at work is to deploy and test in different environments. Deploying a web application is definitely a nightmare. Even if I migrate to a UNIX-based platform later

Author: Mike Ebinum Translator: ye Keqiang

I am very excited about Docker. As a developer who has been developing. NET for a long time, one of the things I don't like at work is to deploy and test in different environments. Deploying a web application is definitely a nightmare. Even if I migrate to UNIX-based development and use open-source tools/languages, such as Node, Java, Scala, and PHP, I find that the same deployment problem occurs again and again.

With tools such as Docker, you can make the configuration of the development environment exactly the same as that of the production environment. After the web application container is deployed, everything is configured, so you don't have to worry about the troubles of deployment.

If you are a newbie to Docker and are not very sure what it is, the following article will be a perfect learning outline ..

  • Docker Lightweight linux containers for consistent development and deployment
  • Docker: Using Linux Containers to Support Portable Application deployment

As a lazy programmer, my dream has come true. Once it is done, there will be no worries (to some extent ). This article demonstrates how to create and run a Docker container based on the following development environments.

  • CentOS
  • Nginx web server
  • PHP with Hip Hop VM (HHVM)
Dockerfile

Prepare to start, we createDockerfile-- Dockerfile contains instructions on how to create the required image.

FROM    centos:centos6MAINTAINER Mike Ebinum, hello@seedtech.io  
Use Cent OS 6.x

Notify Docker to use the latest CentOS 6.x available image in the official community.

Update Image

Install the latest version of the package and add the repository of Red Hat EPEL to the available repository list.

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"  
Installation Package

Installsupervisord-- We will use this configuration to control the processes running in the container-nginx, php, some PHP Development kits, and Facebook's 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"]  
Configure Nginx, HHVM, and Supervisord

Create a directory for nginx andindex.phpAdd the file to nginx for display.

RUN mkdir -p /var/www/html && chmod a+r /var/www/html && echo "
 " > /var/www/html/index.php  

The next group of commands is:

  • Add a configuration file for HHVM and restart our HHVM service.
  • Add a configuration file for Supervisord, and then start Nginx and 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
  • Add a shell script/run.sh, Started when the Docker container is running.

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"]

Build a container and tag

docker build -t centos-nginx-php5-hhvm .  

Now we have a full-featured container, which can run as follows:

docker run -d -p 80:80 centos-nginx-php5-hhvm  

If your local service is running and port 80 is occupied, you can easily change the external port of the container.

Docker registry provides the available version of this Docker image.

Dockerfile

The complete Dockerfile is as follows:

# 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"]  

Other available files mentioned in this article are on Github.

Next?

Great! Now we have an environment configuration, but how do I run the PHP application? I will introduce how to use this container to install and configure PHP applications. You are welcome to subscribe to this blog. You can also follow @ mikeebinum and @ SEEDtechio on twitter for updates.

This article was written by Mike Ebinum and translated by Ye Keqiang. Click here to read the original article. The article was contributed by Mike Ebinum, click here to read the original publication.

Original article address: Create a Docker container running PHP, NGINX, and Hip Hop VM (HHVM). Thank you for sharing it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.