您的位置 首页 docker

使用Dockerfile构建WordPress实战案例解法一

使用Dockerfile构建WordPress实战案例解法一

 

build.sh 内容:

#!/bin/bash


docker container rm -f `docker container ps -qa`
docker build -t wp:v0.$1 .
docker run -dp 80:80 wp:v0.$1
docker ps -l

 

dockerfile  内容

FROM centos:7

LABEL school=baimei \
      class=dashu \
      office=www.baimei.com

# 配置国内软件源
RUN curl -s -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && \
    sed -i -e '/mirrors.cloud.aliyuncs.com/d' \ 
           -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo && \
    curl  -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

# 安装php,nginx,sshd,mysql-mariadb
RUN yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm && \
    yum -y install php74-php-cli php74-php-common php74-php-devel php74-php-embedded php74-php-fpm php74-php-gd php74-php-mbstring php74-php-mysqlnd php74-php-pdo php74-php-opcache php74-php-xml php74-php-soap nginx mariadb-server && \
    ln -s /opt/remi/php74/root/usr/bin/php /usr/local/bin/php && \
    rm -rf /var/cache/yum


# 修改PHP的运行用户和nginx是相同的用户,否则服务器报错500
RUN sed -ri '/^group/s/(group = )apache/\1nginx/' /etc/opt/remi/php74/php-fpm.d/www.conf && \
    sed -ri '/^user/s/(user = )apache/\1nginx/' /etc/opt/remi/php74/php-fpm.d/www.conf && \
    install -d /baimei/wp -o nginx -g nginx


# 拷贝配置文件
COPY config/wp.conf /etc/nginx/conf.d/wp.conf

# 拷贝测试PHP环境
#COPY softwares/phpinfo.php /baimei/wp
#COPY softwares/mysql.php  /baimei/wp/

# 拷贝启动脚本
COPY script/start.sh /

# 将WordPress软件包拷贝到nginx的站点目录
ADD softwares/wordpress-6.2.2.tar.gz /baimei/wp

# 给nginx用户授权WordPress站点目录的访问权限
RUN chown nginx:nginx -R /baimei/wp/wordpress

EXPOSE 80 

# CMD ["tail","-f","/etc/hosts"]
CMD ["bash","-x","/start.sh"]

 

start.sh 内容

#!/bin/bash

# 启动php
/opt/remi/php74/root/usr/sbin/php-fpm

# 启动nginx
# nginx -g "daemon off;"
nginx

# 初始化并启动mariadb,需要一定的时间
/usr/libexec/mariadb-prepare-db-dir
/usr/bin/mysqld_safe --basedir=/usr &

# 初始化MySQL的密码
sleep 3
/usr/bin/mysqladmin -u root password 'baimei'

# 创建数据库
mysql -pbaimei -e "CREATE DATABASE wordpress;"

# 阻塞容器,防止容器退出
tail -f /etc/hosts

 

wp.conf 内容

server {
   listen 80;
   server_name wp.baimei.com;
   # root /baimei/wp;
   root /baimei/wp/wordpress;
   index index.html index.php;
 
  location ~ \.php$ {
     fastcgi_pass 127.0.0.1:9000;
     fastcgi_index index.php;
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     include fastcgi_params;
  }
}

 

docker自动构建wordpress 方案1:下载

https://url69.ctfile.com/d/253469-56449628-7b4c87?p=2206

(访问密码: 2206)

http://10.0.0.201/wp-admin/setup-config.php

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章