1. 安装 Docker
在我们真正开始之前,我们需要确保在我们的 Linux 机器上已经安装了 Docker。我们使用的主机是 CentOS 7,因此我们用下面的命令使用 yum 管理器安装 docker。
2. 创建 wordpress 的 Dockerfile
我们需要创建用于自动安装 wordpress 以及其前置需求的 Dockerfile。这个 Dockerfile 将用于构建 wordpress 的安装镜像。这个 wordpress Dockerfile 会从 Docker Registry Hub 获取 CentOS 7 镜像并用最新的可用更新升级系统。然后它会安装必要的软件,例如 Nginx Web 服务器、PHP、MariaDB、Open SSH 服务器,以及其它保证 Docker 容器正常运行不可缺少的组件。最后它会执行一个初始化 wordpress 安装的脚本。
然后,我们需要将下面的配置行添加到 Dockerfile中。
<div class="jb51code">
<pre class="brush:plain;">
FROM centos:centos7
MAINTAINER The CentOS Project cloud-ops@centos.org
RUN yum -y update; yum clean all
RUN yum -y install epel-release; yum clean all
RUN yum -y install mariadb mariadb-server mariadb-client Nginx PHP-fpm PHP-cli PHP-MysqL PHP-gd PHP-imap PHP-ldap PHP-odbc PHP-pear PHP-xml PHP-xmlrpc PHP-magickwand PHP-magpieRSS PHP-mbstring PHP-mcrypt PHP-mssql PHP-shout PHP-snmp PHP-soap PHP-tidy PHP-apc pwgen python-setuptools curl git tar; yum clean all
ADD ./start.sh /start.sh
ADD ./Nginx-site.conf /Nginx.conf
RUN mv /Nginx.conf /etc/Nginx/Nginx.conf
RUN rm -rf /usr/share/Nginx/html/
RUN /usr/bin/easy_install supervisor
RUN /usr/bin/easy_install supervisor-stdout
ADD ./supervisord.conf /etc/supervisord.conf
RUN echo %sudo ALL=nopASSWD: ALL >> /etc/sudoers
ADD http://wordpress.org/latest.tar.gz /wordpress.tar.gz
RUN tar xvzf /wordpress.tar.gz
RUN mv /wordpress/ /usr/share/Nginx/html/.
RUN chown -R apache:apache /usr/share/Nginx/
RUN chmod 755 /start.sh
RUN mkdir /var/run/sshd
EXPOSE 80
EXPOSE 22
CMD ["/bin/bash","/start.sh"]