您现在的位置是:首页 > 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主题,通常都是使用的Google字体,但是你用在中文网站上后,中文字都是宋体,与网站的主题很不搭调,怎么修改呢?
wordpress建网站的方法和步骤
域名就是一个网站的地址,例如 .baidu.com即为百度。购买域名可以到一些知名的网站去购买,例如万网,请首先考虑好域名的名字, 非常重要。
wordpress中文乱码的解决方法
记录一下,希望对别人也有作用公司因为业务需要,需要做一个网站,主要是内容展示,内容管理,所以我选择了WordPress系统作为该网站。环境Red Hat Enterprise Linux 5 RPM (x86)
wordpress访问不了,WordPress后台无法访问的解决方法
wordpress访问不了的解决办法:1、通过FTP或者宝塔面板进入服务器;2、把文件plugins重命名为“plugins123”;3、停用所有WordPress插件
相关源码
-
(PC+WAP)绣花刺绣传统手工工艺pbootcms网站源码下载这款基于PbootCMS的网站模板为刺绣和传统手工艺行业设计,采用优雅的布局和精致的细节处理,能够呈现手工艺品的独特韵味和文化内涵。模板结构合理,功能完善,是手工艺从业者展示作品的理想选择。查看源码 -
(自适应响应式)陶瓷研磨盘抛光机械设备pbootcms网站模板本模板基于PbootCMS系统开发,为研磨抛光设备制造企业设计,特别适合陶瓷研磨盘、抛光设备等表面处理设备展示。采用响应式布局技术,确保各类设备的参数和工艺在不同终端上都能清晰呈现。查看源码 -
(自适应响应式)英文外贸电子产品手机配件网站pbootcms模板专业级外贸网站模板基于PbootCMS内核开发,为电子产品跨境贸易企业设计。采用响应式布局技术,确保电脑、平板、手机等设备访问时自动适配显示效果。数据实时同步管理,一次编辑全平台生效。查看源码 -
pbootcms模板(PC+WAP)传媒广告影视公司网站源码基于PbootCMS内核开发的全自适应传媒文化网站模板,为影视公司、广告传媒企业打造,同时支持多行业快速适配。通过替换文字图片即可转换为其他行业网站查看源码 -
(自适应)大气壁挂炉暖气设备家用电器模板带加盟申请和下载资料为壁挂炉、暖气片等供暖设备企业设计的PbootCMS模板,通过响应式技术实现跨终端展示产品参数和技术细节。后台统一管理确保采暖系统数据、服务网点信息实时同步更新查看源码 -
自适应响应式绿色装修公司定制家居类pbootcms网站下载(自适应手机端)响应式全屋装修定制家居类网站pbootcms模板 绿色装修公司网站源码下载PbootCMS内核开发的网站模板,该模板适用于装修定制网站、装查看源码
| 分享笔记 (共有 篇笔记) |

