国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【云原生】Dockerfile制作WordPress鏡像,實現(xiàn)Compose + K8s編排部署

這篇具有很好參考價值的文章主要介紹了【云原生】Dockerfile制作WordPress鏡像,實現(xiàn)Compose + K8s編排部署。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

【云原生】Dockerfile制作WordPress鏡像,實現(xiàn)Compose + K8s編排部署

?? 關(guān)于作者


大家好,我是秋意零。

?? CSDN作者主頁

  • ?? 博客主頁

?? 簡介

  • ?? 普通本科生在讀
  • 在校期間參與眾多計算機相關(guān)比賽,如:?? “省賽”、“國賽”,斬獲多項獎項榮譽證書
  • ?? 各個平臺,秋意臨 賬號創(chuàng)作者
  • ?? 云社區(qū) 創(chuàng)建者
點贊、收藏+關(guān)注下次不迷路!

歡迎加入云社區(qū)


前言

今天給各位帶來一個出色網(wǎng)站、博客系統(tǒng) WordPress,不過不使用 Docker Hub 提供的 WordPress Docker鏡像,我們使用 Dockerfile 自己制作,實現(xiàn) LNMP WordPress 運行環(huán)境,并將 WordPress 部署再其基礎(chǔ)之上

為什么不使用 Docker Hub 提供的 WordPress 鏡像部署呢?

環(huán)境準(zhǔn)備

  • Linux 7.5
  • docker v23.0.1
  • docker compose v2.17.0
  • WordPress v6.2

注意:這里的環(huán)境是博主使用環(huán)境,不限于此

新手小白教程

Centos7.5安裝教程
Docker安裝教程
Docker-Compose安裝教程

目錄結(jié)構(gòu)

[root@master01 ~]# tree docker
docker
├── db.sh   #數(shù)據(jù)庫啟動、配置腳本
├── 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配置文件,這里主要配置數(shù)據(jù)庫部分
└── yum.sh  #yum源配置腳本

0 directories, 8 files

dockerfile制作鏡像

yum 腳本

yum腳本是兩個 dockerfile 文件公用的腳本,因為這里都是使用 yum 安裝的服務(wù)

# 清除默認(rèn)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 構(gòu)建鏡像時所需要的文件

db.sh 啟動配置腳本

db.sh 是數(shù)據(jù)庫啟動、設(shè)置密碼、創(chuàng)建數(shù)據(jù)庫以及授權(quán)的腳本

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

構(gòu)建鏡像

docker build -t wp-mariadb:v1 -f Dockerfile-mariadb .

Dockerfile-service 鏡像

yum.sh、default.conf 、wp-config.php 是 Dockerfile-service 構(gòu)建鏡像時所需要的文件

default.conf

這是配置 nginx 能代理 php 網(wǎng)頁的配置

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 配置文件無法自動寫入時,使用這種方式手動寫入(主要配置數(shù)據(jù)庫部分)

注意:數(shù)據(jù)庫部分的配置

【云原生】Dockerfile制作WordPress鏡像,實現(xiàn)Compose + K8s編排部署

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' ); # 根據(jù)自己數(shù)據(jù)庫修改

/** Database username */
define( 'DB_USER', 'root' );  # 根據(jù)自己數(shù)據(jù)庫修改

/** Database password */
define( 'DB_PASSWORD', '000000' ); # 根據(jù)自己數(shù)據(jù)庫修改

/** Database hostname */
define( 'DB_HOST', 'mariadb:3306' );  # 這個 mariadb 對應(yīng) compose 里面的服務(wù)名

/** 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 /opt

COPY 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環(huán)境
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 -v

RUN 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

# 為了進(jìn)入特權(quán)模式,所要運行的環(huán)境
CMD /usr/sbin/init
EOF

構(gòu)建鏡像

docker build -t wp-service:v1 -f Dockerfile-service .

docker compose 編排

使用上述構(gòu)建的鏡像編排容器

cat > docker-compose.yaml << EOF
version: '3'
services:
  mariadb:
    image: wp-mariadb:v1
    container_name: db
    ports:
    - 3306:3306
  wordpress:
    image: wp-service:v1
    container_name: wordpress
    privileged: true # 開啟容器特權(quán)模式
    ports:
    - 80:80
    links:
    - mariadb  # 服務(wù)名
    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

進(jìn)入 wordpress 容器啟動 php-fpm、nginx

因為這里使用的 yum 源安裝的(其他方式也可以),沒有php-fpm二進(jìn)制命令啟動 php-fpm 服務(wù),而使用 systemctl 啟動服務(wù)需要權(quán)限,也就是 compose 里面的 privileged: true 字段和 Dockerfile-service 里面的 CMD /usr/sbin/init,這樣就能保證在容器使用systemctl啟動服務(wù)了

docker exec -it wordpress bash
systemctl restart php74-php-fpm
systemctl restart nginx

瀏覽器訪問 80 端口,安裝 wordpress

【云原生】Dockerfile制作WordPress鏡像,實現(xiàn)Compose + K8s編排部署

【云原生】Dockerfile制作WordPress鏡像,實現(xiàn)Compose + K8s編排部署

【云原生】Dockerfile制作WordPress鏡像,實現(xiàn)Compose + K8s編排部署

K8s部署

svc

使用 svc 暴露服務(wù)

[root@master01 wordpress]# cat service.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: mariadb
  name: mariadb
spec:
  clusterIP: None
  selector:
    app: mariadb
  type: ClusterIP
  ports:
  - port: 3306

---
apiVersion: v1
kind: Service
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  ports:
    - port: 80
  selector:
    app: wordpress
  type: NodePort

deploy

包含 mariadb 和 wordpress 服務(wù)

[root@master01 wordpress]# cat deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: mariadb
  name: mariadb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mariadb
  template:
    metadata:
      labels:
        app: mariadb
    spec:
      containers:
      - image: wp-mariadb:v1
        name: mariadb
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: wordpress
  name: wordpress
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wordpress
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      containers:
      - image: wp-service:v1
        name: wordpress
        securityContext:
          privileged: true

進(jìn)入WordPress pod 啟動 php-fpm、nginx 服務(wù)

[root@master01 wordpress]# kubectl get pod
NAME                         READY   STATUS        RESTARTS      AGE
mariadb-5cd9b8655d-cq8nd     1/1     Running       0             4s
wordpress-744964c4cb-sk47g   1/1     Running       0             4s
[root@master01 wordpress]# kubectl exec -it pod/wordpress-744964c4cb-sk47g -- bash
[root@wordpress-744964c4cb-sk47g opt]# systemctl restart php74-php-fpm
[root@wordpress-744964c4cb-sk47g opt]# systemctl restart nginx

瀏覽器訪問

[root@master01 wordpress]# kubectl get svc
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP        21d
mariadb      ClusterIP   None            <none>        3306/TCP       10h
wordpress    NodePort    10.97.150.148   <none>        80:32214/TCP   10h

【云原生】Dockerfile制作WordPress鏡像,實現(xiàn)Compose + K8s編排部署

? 最后


?? 我是秋意臨,歡迎大家一鍵三連、加入云社區(qū)

?? 我們下期再見(⊙o⊙)!??!文章來源地址http://www.zghlxwxcb.cn/news/detail-438661.html


到了這里,關(guān)于【云原生】Dockerfile制作WordPress鏡像,實現(xiàn)Compose + K8s編排部署的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 【Dockerfile鏡像實戰(zhàn)】構(gòu)建LNMP環(huán)境并運行Wordpress網(wǎng)站平臺

    【Dockerfile鏡像實戰(zhàn)】構(gòu)建LNMP環(huán)境并運行Wordpress網(wǎng)站平臺

    公司在實際的生產(chǎn)環(huán)境中,需要使用Docker 技術(shù)在一臺主機上 創(chuàng)建LNMP服務(wù)并運行Wordpress網(wǎng)站平臺 。 然后對此服務(wù)進(jìn)行相關(guān)的性能調(diào)優(yōu)和管理工作 主機 操作系統(tǒng) IP地址 主要軟件 宿主機 CentOS 7.3 x86_64 192.168.2.106 Docker 19.03 Nginx容器 172.18.0.10 Mysql容器 172.18.0.20 PHP容器 172.18.0.30 容

    2024年02月08日
    瀏覽(19)
  • [云原生1. ] 使用Docker-compose一鍵部署Wordpress平臺

    [云原生1. ] 使用Docker-compose一鍵部署Wordpress平臺

    docker-compose 是實現(xiàn)在單機上對容器集群編排管理的工具。 docker-compose 是基于python開發(fā)的,能運行docker的平臺,都能用docker-compose編排管理容器。 本質(zhì)就是在 yaml格式 的 docker-compose配置模板文件 里定義多個容器的啟動參數(shù)和依賴關(guān)系,并使用 docker-compose 根據(jù)這個模板文件的配

    2024年02月07日
    瀏覽(58)
  • Docker | 使用Dockerfile制作鏡像

    Docker | 使用Dockerfile制作鏡像

    ?作者簡介:大家好,我是Leo,熱愛Java后端開發(fā)者,一個想要與大家共同進(jìn)步的男人???? ??個人主頁:Leo的博客 ??當(dāng)前專欄:Docker系列 ?特色專欄: MySQL學(xué)習(xí) ??本文內(nèi)容: Docker | 使用Dockerfile制作鏡像 ??個人知識庫: [Leo知識庫]https://gaoziman.gitee.io/blogs/),歡迎大家訪

    2024年02月04日
    瀏覽(96)
  • docker (八)-dockerfile制作鏡像

    docker (八)-dockerfile制作鏡像

    dockerfile通常包含以下幾個常用命令: FROM ? 打包使用的基礎(chǔ)鏡像 WORKDIR?? 相當(dāng)于cd命令,進(jìn)入工作目錄 COPY ? 將宿主機的文件復(fù)制到容器內(nèi) RUN?? 打包時執(zhí)行的命令,相當(dāng)于打包過程中在容器中執(zhí)行shell腳本,通常用來安裝應(yīng)用程序所需要的依賴、設(shè)置權(quán)限、初始化配置文件

    2024年02月21日
    瀏覽(96)
  • Dockerfile制作LAMP環(huán)境鏡像

    Dockerfile制作LAMP環(huán)境鏡像

    編寫Dockerfile 不修改默認(rèn)頁面 修改默認(rèn)頁面 該Dockerfile在宿主機安裝有GUI時通過瀏覽器可看出效果。 Start Script 目錄結(jié)構(gòu)及文件 登錄私有倉庫 給鏡像打標(biāo)簽 上傳鏡像 頁面檢查 檢測鏡像可用性

    2024年02月11日
    瀏覽(44)
  • Dockerfile如何制作mysql鏡像

    Dockerfile如何制作mysql鏡像

    Docker是一個開源的應(yīng)用容器引擎,讓開發(fā)者可以打包他們的應(yīng)用以及依賴包到一個可抑制的容器中,然后發(fā)布到任何流行的Linux機器上,也可以實現(xiàn)虛擬化。 1. 編寫dockerfile_mysql5.7 在文件夾/root/dockerfile/mysql創(chuàng)建文件dockerfile_mysql5.7 這里是先導(dǎo)入數(shù)據(jù),然后才是設(shè)置用戶和權(quán)限

    2024年02月06日
    瀏覽(21)
  • Dockerfile制作Nginx應(yīng)用鏡像

    Dockerfile制作Nginx應(yīng)用鏡像

    創(chuàng)建Dockerfile 創(chuàng)建鏡像 上傳鏡像-harbor 修改hosts文件 修改daemon.json 重啟DOCKER 登錄并上傳 測試鏡像

    2024年02月12日
    瀏覽(55)
  • 【云原生 | 15】Dockerfile構(gòu)建鏡像實戰(zhàn)

    【云原生 | 15】Dockerfile構(gòu)建鏡像實戰(zhàn)

    ?? 博主簡介 : ??????????云計算領(lǐng)域優(yōu)質(zhì)創(chuàng)作者 ??????????2022年CSDN新星計劃python賽道第一名 ??????????2022年CSDN原力計劃優(yōu)質(zhì)作者 ??????????阿里云ACE認(rèn)證高級工程師 ??????????阿里云開發(fā)者社區(qū)專家博主 ?? 交流社區(qū) :CSDN云計算交流社區(qū)歡迎您的

    2024年02月22日
    瀏覽(22)
  • 【云原生】Docker鏡像的創(chuàng)建,Dockerfile

    【云原生】Docker鏡像的創(chuàng)建,Dockerfile

    創(chuàng)建鏡像有三種方法,分別為【基于已有鏡像創(chuàng)建】、【基于本地模板創(chuàng)建】以及【基于Dockerfile創(chuàng)建】。? 通過導(dǎo)入操作系統(tǒng)模板文件可以生成鏡像,模板可以從OPENVZ 開源項目下載,下載地址為:? ?openvz.org/?Download/template/precreated ?聯(lián)合文件系統(tǒng)(UnionFS )? Union文件系統(tǒng)是

    2024年02月15日
    瀏覽(26)
  • Dockerfile制作鏡像與搭建LAMP環(huán)境

    Dockerfile制作鏡像與搭建LAMP環(huán)境

    具體要求如下: (1)基于centos基礎(chǔ)鏡像; (2)指定作者信息; (3)安裝nginx服務(wù),將提供的dest目錄(提供默認(rèn)主頁index.html)傳到鏡像內(nèi),并將dest目錄內(nèi)的前端文件復(fù)制到nginx的工作目錄; (4)暴露80端口; (5)設(shè)置服務(wù)自啟動。 (6)驗證鏡像。 [root@localhost nginx]# ca

    2024年02月12日
    瀏覽(29)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包