【云原生】Dockerfile制作WordPress镜像,实现compose编排部署
文章目录
- 👹 关于作者
- 前言
- 环境准备
- 目录结构
- dockerfile制作镜像
- yum 脚本
- Dockerfile-mariadb 镜像
- Dockerfile-service 镜像
- docker compose 编排
- 提升
- ✊ 最后

👹 关于作者
大家好,我是秋意临。
😈 CSDN作者主页
- 😎 博客主页
👿 简介
- 👻 普通本科生在读
- 在校期间参与众多计算机相关比赛,如:🌟 “省赛”、“国赛”,斩获多项奖项荣誉证书
- 🔥 各个平台,秋意临 账号创作者
- 🔥 云社区 创建者
点赞、收藏+关注下次不迷路!
欢迎加入云社区
前言
今天给各位带来一个出色网站、博客系统 WordPress,不过不使用 Docker Hub 提供的 WordPress Docker镜像,我们使用 Dockerfile 自己制作,实现 LNMP WordPress 运行环境,并将 WordPress 部署再其基础之上
为什么不使用 Docker Hub 提供的 WordPress 镜像部署呢?
环境准备
- Linux 7.5
- docker v23.0.1
- docker compose v2.17.0
- WordPress v6.2
注意:这里的环境是博主使用环境,不限于此
新手小白教程
Centos7.5安装教程
Docker安装教程
Docker-Compose安装教程
目录结构
[root@master01 ~]# tree docker
docker
├── db.sh #数据库启动、配置脚本
├── default.conf #nginx配置文件,配置支持 php
├── docker-compose.yaml # compose 文件
├── Dockerfile-mariadb # maraidb dockerfile文件
├── Dockerfile-service # nginx+php+wordpress dockerfile文件
├── wordpress-6.2-zh_CN.zip # wordpress安装包
├── wp-config.php # wordpress配置文件,这里主要配置数据库部分
└── yum.sh #yum源配置脚本0 directories, 8 files
dockerfile制作镜像
yum 脚本
yum脚本是两个 dockerfile 文件公用的脚本,因为这里都是使用 yum 安装的服务
# 清除默认yum
rm -rf /etc/yum.repos.d/*# 阿里云 centos7 yum
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo#nginx yum
cat > /etc/yum.repos.d/nginx.repo << EOF
[nginx]
name=nginx
baseurl=https://nginx.org/packages/centos/7/x86_64/
gpgcheck=0
enabled=1
EOF#mariadb yum
cat > /etc/yum.repos.d/mariadb.repo <<EOF
[mariadb]
name=mariadb
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.5.19/yum/centos/7/x86_64/
gpgcheck=0
enabled=1
EOF#php yum
yum -y install epel-release
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Dockerfile-mariadb 镜像
yum.sh、db.sh 是 Dockerfile-mariadb 构建镜像时所需要的文件
db.sh 启动配置脚本
db.sh 是数据库启动、设置密码、创建数据库以及授权的脚本
cat > db.sh << EOF
#!/bin/bash
mysql_install_db --user=root
mysqld_safe --user=root &
sleep 3
mysqladmin -u root password '000000'
mysql -uroot -p000000 -e "create database wordpress;"
mysql -uroot -p000000 -e "grant all on wordpress.* to root@localhost identified by '000000';"
mysql -uroot -p000000 -e "grant all on wordpress.* to root@'%' identified by '000000';"
EOF
Dockerfile-mariadb
cat > Dockerfile-mariadb << EOF
FROM centos:centos7.9.2009
MAINTAINER qyl
COPY yum.sh /opt/
COPY db.sh /opt
RUN sh /opt/yum.sh && yum clean all
RUN yum install -y mariadb-server
RUN sh /opt/db.sh
EXPOSE 3306
CMD ["mysqld_safe","--user=root"]
EOF
构建镜像
docker build -t wp-mariadb:v1 -f Dockerfile-mariadb .
Dockerfile-service 镜像
yum.sh、default.conf 、wp-config.php 是 Dockerfile-service 构建镜像时所需要的文件
default.conf
这是配置 nginx 能代理 php 网页的配置
cat > default.conf << EOF
server {listen 80;server_name localhost;location / {root /usr/share/nginx/html;index index.php index.html index.htm; #修改部分}error_page 500 502 503 504 /50x.html;location = /50x.html {root /usr/share/nginx/html;}location ~ \.php$ {root /usr/share/nginx/html; #修改部分fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #修改部分include fastcgi_params;}
}
EOF
wp-config.php
在安装 wordpress 时 wordpress 配置文件无法自动写入时,使用这种方式手动写入(主要配置数据库部分)
注意:数据库部分的配置

cat > wp-config.php << EOF
<?php
/*** The base configuration for WordPress** The wp-config.php creation script uses this file during the installation.* You don't have to use the web site, you can copy this file to "wp-config.php"* and fill in the values.** This file contains the following configurations:** * Database settings* * Secret keys* * Database table prefix* * ABSPATH** @link https://wordpress.org/documentation/article/editing-wp-config-php/** @package WordPress*/// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' ); # 根据自己数据库修改/** Database username */
define( 'DB_USER', 'root' ); # 根据自己数据库修改/** Database password */
define( 'DB_PASSWORD', '000000' ); # 根据自己数据库修改/** Database hostname */
define( 'DB_HOST', 'mariadb:3306' ); # 这个 mariadb 对应 compose 里面的服务名/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );/**#@+* Authentication unique keys and salts.** Change these to different unique phrases! You can generate these using* the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.** You can change these at any point in time to invalidate all existing cookies.* This will force all users to have to log in again.** @since 2.6.0*/
define( 'AUTH_KEY', 'put your unique phrase here' );
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
define( 'NONCE_KEY', 'put your unique phrase here' );
define( 'AUTH_SALT', 'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
define( 'NONCE_SALT', 'put your unique phrase here' );/**#@-*//*** WordPress database table prefix.** You can have multiple installations in one database if you give each* a unique prefix. Only numbers, letters, and underscores please!*/
$table_prefix = 'wp_';/*** For developers: WordPress debugging mode.** Change this to true to enable the display of notices during development.* It is strongly recommended that plugin and theme developers use WP_DEBUG* in their development environments.** For information on other constants that can be used for debugging,* visit the documentation.** @link https://wordpress.org/documentation/article/debugging-in-wordpress/*/
define( 'WP_DEBUG', false );/* Add any custom values between this line and the "stop editing" line. *//* That's all, stop editing! Happy publishing. *//** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {define( 'ABSPATH', __DIR__ . '/' );
}/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
EOF
Dockerfile-service
cat > Dockerfile-service << EOF
FROM centos:centos7.9.2009
MAINTAINER qyl
WORKDIR /optCOPY wordpress-6.2-zh_CN.zip ./
COPY yum.sh /opt/
RUN sh /opt/yum.sh
RUN yum clean all &&\yum install -y nginx unzip &&\unzip ./wordpress-6.2-zh_CN.zip# 安装php7.4环境
RUN yum install -y php74-php-devel php74-php php74-php-cli php74-php-common php74-php-gd php74-php-ldap php74-php-mbstring php74-php-mcrypt php74-php-pdo php74-php-mysqlnd php74-php-fpm php74-php-opcache php74-php-pecl-redis php74-php-pecl-mongodb php74-php-fpm#修改 php-fpm 的用户和组为nginx
RUN sed -i 's/^user\ =\ apache/user\ =\ nginx/g' /etc/opt/remi/php74/php-fpm.d/www.conf && \sed -i 's/^group\ =\ apache/group\ =\ nginx/g' /etc/opt/remi/php74/php-fpm.d/www.conf &&\php74 -vRUN rm -rf /usr/share/nginx/html/* &&\cp -rf ./wordpress/* /usr/share/nginx/html/COPY default.conf /etc/nginx/conf.d/default.conf
COPY wp-config.php /usr/share/nginx/html/
EXPOSE 80# 为了进入特权模式,所要运行的环境
CMD /usr/sbin/init
EOF
构建镜像
docker build -t wp-service:v1 -f Dockerfile-service .
docker compose 编排
使用上述构建的镜像编排容器
cat > docker-compose.yaml << EOF
version: '3'
services:mariadb:image: wp-mariadb:v1container_name: dbports:- 3306:3306wordpress:image: wp-service:v1container_name: wordpressprivileged: true # 开启容器特权模式ports:- 80:80links:- mariadb # 服务名depends_on:- mariadb
EOF
compose 启动容器
[root@master01 docker]# docker compose up -d
[+] Running 3/3✔ Network docker_default Created 0.1s✔ Container db Started 0.6s✔ Container wordpress Started 1.3s[root@master01 docker]# docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
db wp-mariadb:v1 "mysqld_safe --user=…" mariadb About a minute ago Up About a minute 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp
wordpress wp:v1 "/bin/sh -c /usr/sbi…" wordpress About a minute ago Up About a minute 0.0.0.0:80->80/tcp, :::80->80/tcp
进入 wordpress 容器启动 php-fpm、nginx
因为这里使用的 yum 源安装的(其他方式也可以),没有php-fpm二进制命令启动 php-fpm 服务,而使用 systemctl 启动服务需要权限,也就是 compose 里面的
privileged: true字段和 Dockerfile-service 里面的CMD /usr/sbin/init,这样就能保证在容器使用systemctl启动服务了
docker exec -it wordpress bash
systemctl restart php74-php-fpm
systemctl restart nginx
浏览器访问 80 端口,安装 wordpress



提升
如何把 wordpres 部署到 k8s 中呢?
✊ 最后
👏 我是秋意临,欢迎大家一键三连、加入云社区
👋 我们下期再见(⊙o⊙)!!!
相关文章:
【云原生】Dockerfile制作WordPress镜像,实现compose编排部署
文章目录👹 关于作者前言环境准备目录结构dockerfile制作镜像yum 脚本Dockerfile-mariadb 镜像Dockerfile-service 镜像docker compose 编排提升✊ 最后👹 关于作者 大家好,我是秋意临。 😈 CSDN作者主页 😎 博客主页…...
五款好用又有趣的WIN10软件推荐
如果你想让你的电脑使用更方便、更有趣、更专业,那么你一定要看看这篇文章,因为我要给你推荐五款好用又有趣的WIN10软件 1.全局搜索——火柴 火柴是一款全局搜索软件,可以让你快速找到你想要的文件、程序、网页等,只需按下AltSp…...
朴素贝叶斯算法
# -*-coding:utf-8-*- """ Author: sunchang Desc: 代码4-7 朴素贝叶斯实现对异常账户检测 """ import numpy as np class NaiveBayesian: def __init__(self, alpha): self.classP dict() self.classP_f…...
【常见CSS扫盲雪碧图】从源码细看CSS雪碧图原理及实现,千字详解【附源码demo下载】
【写在前面】其实估计很多人都听过雪碧图,或者是CSS-Sprite,在很多门户网站就会经常有用到的,之所有引出雪碧图这个概念还得从前端加载多个图片时候页面闪了一下说起,这样给人的视觉效果体验很差,也就借此机会和大家说…...
Java多线程:ThreadLocal源码剖析
ThreadLocal源码剖析 ThreadLocal其实比较简单,因为类里就三个public方法:set(T value)、get()、remove()。先剖析源码清楚地知道ThreadLocal是干什么用的、再使用、最后总结,讲解ThreadLocal采取这样的思路。 三个理论基础 在剖析ThreadLo…...
96、数据的存储
运行实例: 在debug和release两种模式下,进行代码运行,debug下 i 的地址是大于arr[9] 的地址的,release 下i 的地址是小于arr[9] 的地址。原因是:release状态进行了优化处理。 C语言中基本的内置类型 整形数据类型 char …...
@EventListener注解详细使用(IT枫斗者)
EventListener注解详细使用 简介 EventListener是一种事件驱动编程在spring4.2的时候开始有的,早期可以实现ApplicationListener接口, 为我们提供的一个事件监听、订阅的实现,内部实现原理是观察者设计模式;为的就是业务系统逻辑的解耦,提高…...
[c++17新增语言特性] --- [[nodiscard]]和[[maybe_unused]]
1 [[nodiscard]] 介绍和应用示例 [[nodiscard]] 是C++17引入的一个属性(Attribute),它用于向编译器提示一个函数的返回值应该被检查,避免其被忽略或误用。它可以被用于函数、结构体、类、枚举和 typedef 等声明上,表示如果函数返回值未被使用,或者结构体、类、枚举和 type…...
Centos7安装和使用docker的笔记
最近项目要求用容器部署,所以需要将docker的用法搞清楚,在操作过程中,积累了一些操作方法和技巧,作为笔记,为后面使用做个参考。 首先安装docker需要给centos增加源(参考https://www.runoob.com/docker/cen…...
结构像与功能像
导读现代神经成像技术使我们能够研究活体大脑的结构和功能。活体神经成像的益处是显而易见的,而且在基础和临床神经科学中,神经成像已经取得了巨大进展。本文概述了利用活体神经成像研究大脑结构和功能的工作和成就。介绍了几种不同类型的结构MRI成像方法…...
【IAR工程】STM8S基于ST标准库读取DS1302数据
【IAR工程】STM8S基于ST标准库读取DS1302数据✨申明:本文章仅发表在CSDN网站,任何其他网站,未注明来源,见此内容均为盗链和爬取,请多多尊重和支持原创!🍁对于文中所提供的相关资源链接将作不定期更换。&…...
【SpringBoot】实现后端服务器发送QQ邮件验证码的功能
步骤一、添加邮件相关依赖二、配置邮件服务器三、发送邮件PS:SMTP 发送失败的解决方案一、添加邮件相关依赖 在 pom.xml 文件中添加 JavaMail 和 Spring Mail 相关的依赖。示例代码如下: <dependency><groupId>com.sun.mail</groupId&g…...
vue在input中输入后,按回车,提交数据
vue在input中输入后,按回车,提交数据 1.展示效果如下: 2.代码展示: <div><el-input v-model"toAddNameText" keyup.enter.native"toAddName()" placeholder"回车,即新增该竖杆名称…...
【YOLOX】用YOLOv5框架YOLOX
【YOLOX】用YOLOv5框架YOLOX一、新建common_x.py二、修改yolo.py三、新建yolox.yaml四、训练最近在跑YOLO主流框架的对比实验,发现了一个很奇怪的问题,就是同一个数据集,在不同YOLO框架下训练出的结果差距竟然大的离谱。我使用ultralytics公司…...
【python机器学习实验】——逻辑回归与感知机进行线性分类,附可视化结果!
【python机器学习实验】——逻辑回归与感知机进行线性分类,附可视化结果! 下载链接 下载链接 下载链接 可视化效果图: 感知机模型结果为例: 首先,我们有训练数据和测试数据,其每一行为(x,y,label)的形式…...
wps删除的文件怎么恢复
在办公中,几乎每个人都会用到WPS办公软件。它可以帮助我们快速有效地处理各种Word文档、ppt幻灯片、excel表格等。但有文件就会有清理,如果我们不小心删除了wps文件呢?那些wps删除的文件怎么恢复?针对这种情况,小编为大家带来一些恢复WPS文…...
NIO消息黏包和半包处理
1、前言 我们在进行NIO编程时,通常会使用缓冲区进行消息的通信(ByteBuffer),而缓冲区的大小是固定的。那么除非你进行自动扩容(Netty就是这么处理的),否则的话,当你的消息存进该缓冲…...
day018 第六章 二叉树 part05
一、513.找树左下角的值 这个题目的主要思路是使用广度优先搜索(BFS)遍历整棵树,最后返回最后一层的最左边的节点的值。具体的实现可以使用队列来存储每一层的节点,并且在遍历每一层节点时,不断更新最左边的节点的值。…...
如何下载ChatGPT-ChatGPT如何写作
CHATGPT能否改一下文章 ChatGPT 作为一种自然语言处理技术,生成的文章可能存在表达不够准确或文风不符合要求等问题。在这种情况下,可以使用编辑和修改来改变输出的文章,使其符合特定的要求和期望。 具体来说,可以采用以下步骤对…...
微策略再次买入
原创:刘教链* * *隔夜,比特币再次小幅回升至28k上方。微策略(Microstrategy)创始人Michael Saylor发推表示,微策略再次出手,买入1045枚比特币。此次买入大概花费2930万美元,平均加仓成本28016美…...
深入浅出Asp.Net Core MVC应用开发系列-AspNetCore中的日志记录
ASP.NET Core 是一个跨平台的开源框架,用于在 Windows、macOS 或 Linux 上生成基于云的新式 Web 应用。 ASP.NET Core 中的日志记录 .NET 通过 ILogger API 支持高性能结构化日志记录,以帮助监视应用程序行为和诊断问题。 可以通过配置不同的记录提供程…...
地震勘探——干扰波识别、井中地震时距曲线特点
目录 干扰波识别反射波地震勘探的干扰波 井中地震时距曲线特点 干扰波识别 有效波:可以用来解决所提出的地质任务的波;干扰波:所有妨碍辨认、追踪有效波的其他波。 地震勘探中,有效波和干扰波是相对的。例如,在反射波…...
前端倒计时误差!
提示:记录工作中遇到的需求及解决办法 文章目录 前言一、误差从何而来?二、五大解决方案1. 动态校准法(基础版)2. Web Worker 计时3. 服务器时间同步4. Performance API 高精度计时5. 页面可见性API优化三、生产环境最佳实践四、终极解决方案架构前言 前几天听说公司某个项…...
Mybatis逆向工程,动态创建实体类、条件扩展类、Mapper接口、Mapper.xml映射文件
今天呢,博主的学习进度也是步入了Java Mybatis 框架,目前正在逐步杨帆旗航。 那么接下来就给大家出一期有关 Mybatis 逆向工程的教学,希望能对大家有所帮助,也特别欢迎大家指点不足之处,小生很乐意接受正确的建议&…...
FastAPI 教程:从入门到实践
FastAPI 是一个现代、快速(高性能)的 Web 框架,用于构建 API,支持 Python 3.6。它基于标准 Python 类型提示,易于学习且功能强大。以下是一个完整的 FastAPI 入门教程,涵盖从环境搭建到创建并运行一个简单的…...
YSYX学习记录(八)
C语言,练习0: 先创建一个文件夹,我用的是物理机: 安装build-essential 练习1: 我注释掉了 #include <stdio.h> 出现下面错误 在你的文本编辑器中打开ex1文件,随机修改或删除一部分,之后…...
[ICLR 2022]How Much Can CLIP Benefit Vision-and-Language Tasks?
论文网址:pdf 英文是纯手打的!论文原文的summarizing and paraphrasing。可能会出现难以避免的拼写错误和语法错误,若有发现欢迎评论指正!文章偏向于笔记,谨慎食用 目录 1. 心得 2. 论文逐段精读 2.1. Abstract 2…...
postgresql|数据库|只读用户的创建和删除(备忘)
CREATE USER read_only WITH PASSWORD 密码 -- 连接到xxx数据库 \c xxx -- 授予对xxx数据库的只读权限 GRANT CONNECT ON DATABASE xxx TO read_only; GRANT USAGE ON SCHEMA public TO read_only; GRANT SELECT ON ALL TABLES IN SCHEMA public TO read_only; GRANT EXECUTE O…...
rnn判断string中第一次出现a的下标
# coding:utf8 import torch import torch.nn as nn import numpy as np import random import json""" 基于pytorch的网络编写 实现一个RNN网络完成多分类任务 判断字符 a 第一次出现在字符串中的位置 """class TorchModel(nn.Module):def __in…...
scikit-learn机器学习
# 同时添加如下代码, 这样每次环境(kernel)启动的时候只要运行下方代码即可: # Also add the following code, # so that every time the environment (kernel) starts, # just run the following code: import sys sys.path.append(/home/aistudio/external-libraries)机…...
