溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何使用Docker和Traefik搭建WordPress

發(fā)布時(shí)間:2021-11-19 11:49:39 來源:億速云 閱讀:206 作者:小新 欄目:軟件技術(shù)

這篇文章主要為大家展示了“如何使用Docker和Traefik搭建WordPress”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“如何使用Docker和Traefik搭建WordPress”這篇文章吧。

將使用 Docker、Compose、Traefik 對(duì) WordPress 進(jìn)行搭建,完整操作時(shí)間應(yīng)該在十分鐘內(nèi)。
為什么選擇 WordPress
每當(dāng)聊起 CMS 類軟件,聊起社區(qū)資源豐富,不由地會(huì)想到一個(gè)“萬金油”:WordPress ,官方數(shù)據(jù)稱:

Over 60 million people have chosen WordPress to power the place on the web they call “home”

Hundreds of thousands of developers, content creators, and site owners gather at monthly meetups in 436 cities worldwide.

WordPress 為 33% 的互聯(lián)網(wǎng)提供支持。

許多人對(duì)它的印象還停留在執(zhí)行速度慢、安全性差、代碼臃腫的博客系統(tǒng)上。但是事實(shí)上,經(jīng)過十幾年的迭代,它的大版本來到了 5.0 (PHP 主流運(yùn)行時(shí)也來到了 7.0 時(shí)代),性能早已不是問題、安全問題只要做適當(dāng)?shù)姆雷o(hù)能杜絕絕大多數(shù)。

emmm, 代碼確實(shí)還是挺臃腫的。

基于官方鏡像
官方提供了容器鏡像,鏡像下載可以直接使用下面的命令:

docker pull wordpress
1
但是為了更好的配置使用,我們使用 compose 的方式進(jìn)行編排,將下面的內(nèi)容保存為 docker-compose.yml :

version: '3'

services:

  wp:
    image: ${WP_IMAGE}
    restart: always
    networks:
      - traefik
    environment:
        WORDPRESS_DB_HOST: ${DB_HOST}
        WORDPRESS_TABLE_PREFIX: ${WP_DB_PREFIX}
        WORDPRESS_DB_NAME: ${DB_NAME}
        WORDPRESS_DB_USER: ${DB_USER}
        WORDPRESS_DB_PASSWORD: ${DB_PASS}
    volumes:
    # 如果你有定制上傳文件尺寸的需求
    # - ./config/php.conf.uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
      - ./wp-app:/var/www/html
    labels:
      - "traefik.enable=true"
      - "traefik.frontend.rule=Host:${WP_DOMAINS}"
      - "traefik.frontend.entryPoints=https,http"

  mariadb:
    image: ${DB_IMAGE}
    restart: always
    container_name: ${DB_HOST}
    networks:
      - traefik
    environment:
      MYSQL_DATABASE: ${DB_NAME}
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASS}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS}
    volumes:
      - ./data:/var/lib/mysql

  pma:
    image: ${PMA_IMAGE}
    restart: always
    networks:
      - traefik
    environment:
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASS}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS}
      PMA_HOST: ${DB_HOST}
    labels:
      - "traefik.enable=true"
      - "traefik.frontend.rule=Host:${PMA_DOMAIN}"

networks:
  traefik:
    external: true

如果你還不會(huì)使用 Traefik ,可以翻看我之前的文章,這里不做過多贅述。

為了可維護(hù)性,我們將容器鏡像版本信息,應(yīng)用域名,數(shù)據(jù)庫配置等抽象為單獨(dú)的環(huán)境配置文件 .env,內(nèi)容示例:

WP_IMAGE=wordpress:5.1.1-php7.3-apache
WP_DOMAINS=wp.lab.com,wp.lab.io
WP_DB_PREFIX=wp

DB_IMAGE=mariadb:10.3.8
DB_HOST=wp-db
DB_NAME=wordpress
DB_USER=wordpress
DB_PASS=wordpress
DB_ROOT_PASS=soulteary

PMA_IMAGE=phpmyadmin/phpmyadmin:4.8.2
PMA_DOMAIN=pma.wp.lab.com,pma.wp.lab.io

當(dāng)兩個(gè)文件都保存完畢之后,我們執(zhí)行 docker-compose up 命令,你將會(huì)看到許多日志信息,當(dāng)看到類似下面的信息時(shí),WordPress 環(huán)境便準(zhǔn)備就緒啦。

wp-db      |
wp-db      | MySQL init process done. Ready for start up.
wp-db      |
wp-db      | 2019-04-06 16:26:48 0 [Note] mysqld (mysqld 10.3.8-MariaDB-1:10.3.8+maria~jessie) starting as process 1 ...
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Using Linux native AIO
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Uses event mutexes
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Number of pools: 1
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Using SSE2 crc32 instructions
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Completed initialization of buffer pool
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Creating shared tablespace for temporary tables
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: 10.3.8 started; log sequence number 1630833; transaction id 21
wp-db      | 2019-04-06 16:26:48 0 [Note] Plugin 'FEEDBACK' is disabled.
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
wp-db      | 2019-04-06 16:26:48 0 [Note] Server socket created on IP: '::'.
wp-db      | 2019-04-06 16:26:48 0 [Note] InnoDB: Buffer pool(s) load completed at 190406 16:26:48
wp-db      | 2019-04-06 16:26:48 0 [Warning] 'proxies_priv' entry '@% root@e97787886b74' ignored in --skip-name-resolve mode.
wp-db      | 2019-04-06 16:26:48 0 [Note] Reading of all Master_info entries succeded
wp-db      | 2019-04-06 16:26:48 0 [Note] Added new Master_info '' to hash table
wp-db      | 2019-04-06 16:26:48 0 [Note] mysqld: ready for connections.
wp-db      | Version: '10.3.8-MariaDB-1:10.3.8+maria~jessie'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
wp_1       | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.23.0.8. Set the 'ServerName' directive globally to suppress this message

此時(shí)啟動(dòng)瀏覽器,打開我們配置文件中配置好的域名(WP_DOMAIN),便可以開始著名的“三分鐘”安裝了。
填寫適當(dāng)信息,一路 Next ,WordPress 就安裝成功了。
后續(xù)便是具體的應(yīng)用配置,以及性能、安全方面的優(yōu)化啦。
其他
如果你有操作數(shù)據(jù)庫的需求,又不想下載數(shù)據(jù)庫工具或者使用命令行進(jìn)行操作,可以使用 **PHPMyAdmin ** ,同樣的,在瀏覽器中打開之前配置文件中的 PMA 域名地址(PMA_DOMAIN),就可以進(jìn)行操作了。

不過需要注意的是,需要使用 root 和 root password 進(jìn)行登錄,因?yàn)槟J(rèn)情況下,Mariadb 未對(duì)其他用戶賬號(hào)進(jìn)行遠(yuǎn)程訪問授權(quán)。

以上是“如何使用Docker和Traefik搭建WordPress”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI