您现在的位置是:首页 > cms教程 > WordPress教程WordPress教程
docker搭建wordpress博客的实现方法
秋荷2025-03-24WordPress教程已有人查阅
导读环境:centos7、docker、vmwareworkstation虚拟机1 拉取mysql:5.7 镜像,使用mysql镜像运行一容器2 运行容器 查看状态3 拉取wordpress镜像4 运行wordpress 容器,查看状态
环境:centos7、docker、vmwareworkstation虚拟机
1 拉取mysql:5.7 镜像,使用mysql镜像运行一容器
再次进入mysql 容器,使用root用户和密码登录mysql数据库,进入wordpress数据库,再查看是否有表?
有表了
如果遇到问题可以在评论区大家一起讨论一起学习
1 拉取mysql:5.7 镜像,使用mysql镜像运行一容器
[root@server ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
c499e6d256d6: Already exists
22c4cdf4ea75: Pull complete
6ff5091a5a30: Pull complete
2fd3d1af9403: Pull complete
0d9d26127d1d: Pull complete
54a67d4e7579: Pull complete
fe989230d866: Pull complete
466a91a95e2f: Pull complete
3e4554c238f1: Pull complete
603b48ead88c: Pull complete
1e86a9aa7171: Pull complete
Digest: sha256:fbaeced79cfdae5d3c8d4a8c41e883f254f72ed7428c6b93a498824b76d97121
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
2 运行容器 查看状态
[root@localhost ~]# docker run -d --name=mysql-wpx -p 3306:3306 -v /data/mysql:/var/lib/mysql/ -e MYSQL_ROOT_PASSWORD=000000 mysql:5.7
5c0368eaca68bf1df6cebdeaa969b468ca46f8cc16a855098d7aa8189b9fb401
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5c0368eaca68 mysql:5.7 "docker-entrypoint..." 38 seconds ago Up 37 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql-wpx
3 拉取wordpress镜像
[root@server ~]# docker pull wordpress
Using default tag: latest
latest: Pulling from library/wordpress
c499e6d256d6: Already exists
3a635b94b3b9: Pull complete
cf28be682a33: Pull complete
b7118ab6e551: Pull complete
925f628a16b8: Pull complete
a77cff9973b5: Pull complete
9b4f44173a15: Pull complete
c9bd6c436ae3: Pull complete
399316af3112: Pull complete
3cea11f54c61: Pull complete
1ebb66998d8f: Pull complete
ac288a1a6e08: Pull complete
776d750cfd59: Pull complete
a997f5c2f033: Pull complete
a41091590f04: Pull complete
6b1397000eb2: Pull complete
7b387d8d3957: Pull complete
04673b988ee3: Pull complete
0e2da6305da6: Pull complete
f0224352bc00: Pull complete
d5e8b4e26a84: Pull complete
Digest: sha256:191d5caf4ef5b8c57721ade777820f3267654325f7902b2ccd377ceeba1c3fe2
Status: Downloaded newer image for wordpress:latest
docker.io/library/wordpress:latest
4 运行wordpress 容器,查看状态
[root@localhost ~]# docker run -d --name wp-wpx -v /data/wordpress:/var/ /html -e WORDPRESS_DB_HOST=10.1.1.1:3306 -e WORDPRESS_DB_PASSWORD=000000 --link mysql-wpx:mysql -p 8080:80 wordpress
d73e590c48d55963fc3ed9ef82f60f67152c58c7cb15e62d3e6110a8be866e5c
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d73e590c48d5 wordpress "docker-entrypoint..." About a minute ago Up About a minute 0.0.0.0:8080->80/tcp wp-wpx
5c0368eaca68 mysql:5.7 "docker-entrypoint..." 7 minutes ago Up 7 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql-wpx
5 进入wordpress 容器,输入env命令查看环境变量信息
[root@localhost ~]# docker exec -it d7 /bin/bash
root@d73e590c48d5:/var/ /html# env
MYSQL_PORT_33060_TCP_ADDR=172.17.0.2
MYSQL_PORT=tcp://172.17.0.2:3306
MYSQL_PORT_3306_TCP_ADDR=172.17.0.2
MYSQL_NAME=/wp-wpx/mysql
MYSQL_ENV_MYSQL_ROOT_PASSWORD=000000
MYSQL_PORT_3306_TCP_PORT=3306
HOSTNAME=d73e590c48d5
PHP_VERSION=7.3.16
APACHE_CONFDIR=/etc/apache2
PHP_MD5=
PHP_INI_DIR=/usr/local/etc/php
WORDPRESS_VERSION=5.4
GPG_KEYS=CBAF69F173A0FEA4B537F470D66C9593118BCCB6 F38252826ACD957EF380D39F2F7956BC5DA04B5D
MYSQL_ENV_MYSQL_MAJOR=5.7
PHP_LDFLAGS=-Wl,-O1 -Wl,--hash-style=both -pie
MYSQL_PORT_3306_TCP=tcp://172.17.0.2:3306
PWD=/var/ /html
HOME=/root
MYSQL_ENV_GOSU_VERSION=1.7
MYSQL_PORT_33060_TCP_PROTO=tcp
WORDPRESS_SHA1=d5f1e6d7cadd72c11d086a2e1ede0a72f23d993e
PHP_SHA256=91aaee3dbdc71b69b4f3292f9d99211172a2fa926c3f3bbdb0e85dab03dd2bcb
WORDPRESS_DB_HOST=10.1.1.1:3306
PHPIZE_DEPS=autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c
TERM=xterm
PHP_URL=https:// .php.net/get/php-7.3.16.tar.xz/from/this/mirror
MYSQL_PORT_33060_TCP_PORT=33060
PHP_EXTRA_CONFIGURE_ARGS=--with-apxs2 --disable-cgi
MYSQL_PORT_3306_TCP_PROTO=tcp
SHLVL=1
PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
MYSQL_PORT_33060_TCP=tcp://172.17.0.2:33060
WORDPRESS_DB_PASSWORD=000000
APACHE_ENVVARS=/etc/apache2/envvars
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PHP_EXTRA_BUILD_DEPS=apache2-dev
PHP_ASC_URL=https:// .php.net/get/php-7.3.16.tar.xz.asc/from/this/mirror
PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
MYSQL_ENV_MYSQL_VERSION=5.7.29-1debian10
_=/usr/bin/env
使用cat命令查看/etc/hosts文件信息
root@d73e590c48d5:/var/ /html# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 mysql 5c0368eaca68 mysql-wpx
172.17.0.3 d73e590c48d5
使用cat命令查看/var/html/wp-config.php 信息
root@d73e590c48d5:/var/ /html# cat wp-config.php
<?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:
*
* * MySQL settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/
*
* @package WordPress
*/
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress');
/** MySQL database username */
define( 'DB_USER', 'root');
/** MySQL database password */
define( 'DB_PASSWORD', '000000');
/** MySQL hostname */
define( 'DB_HOST', '10.1.1.1:3306');
/** 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', '930c99590c95b2b0a055e020b36df03d32579f6e');
define( 'SECURE_AUTH_KEY', '567bdf94825a641b2e31250720910fb6dc063021');
define( 'LOGGED_IN_KEY', 'b0eac229ec3644d339820ee0be4f9623acc7bfb8');
define( 'NONCE_KEY', 'c8e3147ce9a763bbce44b97e2cbc787df3c35873');
define( 'AUTH_SALT', 'f2f982acd0cbddf91eab764789b66f6e79f27778');
define( 'SECURE_AUTH_SALT', '326022ad7956610343462091fbecdc460e8bab4b');
define( 'LOGGED_IN_SALT', 'd64cbc642f7dc88b29d6f5f3271500ba6623bb4d');
define( 'NONCE_SALT', '2a7aabcdf0838d2d9bc15047bdd4a57b2ae84a81');
/**#@-*/
/**
* 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://developer.wordpress.org/advanced-administration/debug/debug-wordpress/
*/
define( 'WP_DEBUG', false );
// If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact
// see also https://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
}
/* 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';
6 进入mysql 容器,使用root用户和密码登录mysql数据库,查看是否有wordpress数据库?
[root@localhost ~]# docker exec -it 5c /bin/bash
root@5c0368eaca68:/# mysql -uroot -p000000
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.29 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
有wordpress数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| wordpress |
+--------------------+
5 rows in set (0.01 sec)
没有表
mysql> use wordpress;
Database changed
mysql> show tables;
Empty set (0.00 sec)
7 在外网(物理机)的浏览器 使用http:// 容器宿主机的ip:HostPort 访问wordpress站点。再次进入mysql 容器,使用root用户和密码登录mysql数据库,进入wordpress数据库,再查看是否有表?
有表了
mysql> show tables;
+-----------------------+
| Tables_in_wordpress |
+-----------------------+
| wp_commentmeta |
| wp_comments |
| wp_links |
| wp_options |
| wp_postmeta |
| wp_posts |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_termmeta |
| wp_terms |
| wp_usermeta |
| wp_users |
+-----------------------+
12 rows in set (0.00 sec)
之后值得注意的是:wordpress启动后一定要先查看日志看是否启动正常,如果有apache服务启动有问题可能跟docker版本、iptables服务有关,mysql至少要用5.6版本以上不要用太新的版本没那么稳定,这里我用的是拉的是mysql5.7。如果遇到问题可以在评论区大家一起讨论一起学习
本文标签:
很赞哦! ()
相关教程
- Wordpress博客新闻主题在线商店平台betheme 21.5.6版
- linux搭建WordPress博客的方法
- 使用C#转移Wordpress博客到为知笔记或Evernote的方法
- 本地搭建Wordpress博客网站的方法
- linux系统搭建wordpress博客的方法
- 阿里云搭建WordPress博客的方法
- wordpress博客怎么写robots.txt
- Windows搭建Wordpress博客的步骤方法
- socket实现WordPress博客自动发文登录的方法
- centOS服务器怎么搭建wordpress博客
- WordPress博客Centos7+Apache2.4+php5.6+mysql5.5搭建Lamp环境
- Docker怎么搭建WordPress博客
图文教程
wordpress是用什么语言写的
wordpress程序是用PHP语言写成的。WordPress是一个以PHP和MySQL为平台的自由开源的博客软件和内容管理系统。
WordPress根目录.htaccess文件使用方法
有些用户可能还不知道.htaccess文件是什么,所以我们首先来说明一下htaccess的作用。在wordpress的根目录下,你会看到一 个名为.htaccess的文件,它可以是由系统创建、也可以是用
wordpress多站点使用同一个数据库的方法
尚未安装WordPress在初始配置WordPress之前,将wp-config.php中的$table_prefix值(默认为wp_)修改为所需要的表前缀(本文中假设为blog_)
wordpress显示多个分类的文章的方法示例
显示多个分类下的文章可以这样提取:首先把要读取的分类目录的ID找出,放在array数组中。借助强大的query_posts函数实现随机(’orderby’ => ‘rand’)读取十篇(’showposts’ =>10)
相关源码
-
(自适应)代理记账财务会计咨询服务个人公司网站模板该响应式网站模板为代理记账、财政咨询及财务会计类企业设计,基于PbootCMS内核开发。通过自适应手机端的HTML5技术,帮助企业高效构建专业财税服务平台查看源码 -
(带手机版)绿色生态农业种植农产品网站pbootcms源码下载本模板基于PbootCMS内核开发,为生态农业企业量身打造,适用于农业种植、有机农场、农产品电商等业务场景。模板设计充分体现绿色环保理念,突出农业特色,同时保持简洁大气的视觉效果,帮助农业企业建立专业形象。查看源码 -
pbootcms源码宠物类网站源码下载(自适应多端)为宠物装备商店、宠物食品及用品企业打造的营销型模板,基于PbootCMS内核深度开发。采用响应式设计实现PC与移动端适配,PHP7.0+高性能架构支持MySQL/SQLite双数据库查看源码 -
(PC+WAP)蓝色新能源环保太阳能光伏模板pbootcms下载新能源环保行业网站解决方案为太阳能光伏系统企业打造的专业网站模板,助力新能源企业高效展示产品与服务PbootCMS内核开发,源码开放可修改PC与手机端自适应设计查看源码 -
(自适应)中英文双语外贸扬声器音响喇叭话筒网站模板免费下载为音响设备外贸企业设计的中英文双语网站模板,基于PbootCMS内核开发。适配扬声器系统、音频设备等产品的国际化展示需求查看源码 -
(自适应手机端)英文外贸电子产品通用pbootcms模板源码下载为电子产品外贸企业设计的响应式网站模板,采用PbootCMS开发内核,支持多语言展示。模板默认集成产品展示系统、询价表单模块和企业资质展示区,满足跨境贸易基础需求。整站采用模块化设计,便于扩展业务场景。查看源码
| 分享笔记 (共有 篇笔记) |

