关于docker:云原生之使用Docker部署wordpress网站

56次阅读

共计 5973 个字符,预计需要花费 15 分钟才能阅读完成。

@TOC

一、wordpress 介绍

WordPress 是应用 PHP 语言开发的博客平台,用户能够在反对 PHP 和 MySQL 数据库的服务器上架设属于本人的网站。也能够把 WordPress 当作一个内容管理系统(CMS)来应用。

二、查看本地 docker 环境

1. 查看 docker 状态


[root@jeven ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-12-13 23:18:38 CST; 21h ago
     Docs: https://docs.docker.com
 Main PID: 123665 (dockerd)
    Tasks: 86
   Memory: 97.3M
   CGroup: /system.slice/docker.service
           ├─  2022 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3306 -container-ip 192.168.96.2 -container-port...
           ├─  2028 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 3306 -container-ip 192.168.96.2 -container-port 3306...
           ├─  2383 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8090 -container-ip 192.168.96.3 -container-port...
           ├─  2389 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8090 -container-ip 192.168.96.3 -container-port 8090...
           ├─123665 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
           ├─124413 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8777 -container-ip 192.168.144.2 -container-por...
           ├─124432 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8182 -container-ip 172.17.0.2 -container-port 8...
           ├─124433 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8777 -container-ip 192.168.144.2 -container-port 80
           ├─124454 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8182 -container-ip 172.17.0.2 -container-port 8182
           ├─125317 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8030 -container-ip 192.168.160.3 -container-por...
           └─125323 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8030 -container-ip 192.168.160.3 -container-port 800...

Dec 13 23:22:22 jeven dockerd[123665]: time="2022-12-13T23:22:22.561976279+08:00" level=info msg="Container failed to exi...f24c217
Dec 13 23:22:22 jeven dockerd[123665]: time="2022-12-13T23:22:22.964491205+08:00" level=info msg="ignoring event" contain...Delete"Dec 13 23:29:36 jeven dockerd[123665]: time="2022-12-13T23:29:36.757492011+08:00"level=info msg="Container failed to exi...3c63588
Dec 13 23:29:36 jeven dockerd[123665]: time="2022-12-13T23:29:36.813008497+08:00" level=info msg="ignoring event" contain...Delete"Dec 13 23:32:47 jeven dockerd[123665]: time="2022-12-13T23:32:47.610353528+08:00"level=info msg="ignoring event"contain...Delete"
Dec 13 23:32:57 jeven dockerd[123665]: time="2022-12-13T23:32:57.766209632+08:00" level=info msg="Container failed to exi...949f428
Dec 13 23:32:57 jeven dockerd[123665]: time="2022-12-13T23:32:57.820334359+08:00" level=info msg="ignoring event" contain...Delete"Dec 13 23:35:50 jeven dockerd[123665]: time="2022-12-13T23:35:50.839440867+08:00"level=info msg="Container failed to exi...f988de2
Dec 13 23:35:50 jeven dockerd[123665]: time="2022-12-13T23:35:50.891483790+08:00" level=info msg="ignoring event" contain...Delete"Dec 13 23:35:51 jeven dockerd[123665]: time="2022-12-13T23:35:51.480958037+08:00"level=info msg="ignoring event"contain...Delete"
Hint: Some lines were ellipsized, use -l to show in full.

2. 查看 docker 版本

[root@jeven ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:04:24 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 18:02:38 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.12
  GitCommit:        a05d175400b1145e5e6a735a6710579d181e7fb0
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

三、下载 wordpress 镜像


[root@jeven ~]# docker pull wordpress:php7.3
php7.3: Pulling from library/wordpress
php7.3: Pulling from library/wordpress
ae13dd578326: Pull complete 
f15d475049bf: Pull complete 
886e5161983f: Pull complete 
aa7666573a25: Pull complete 
59357a0f9863: Pull complete 
dc3ffb8c774e: Pull complete 
513e9383f6d4: Pull complete 
5ebd0737aa08: Pull complete 
255df6c25392: Pull complete 
f2994be86066: Pull complete 
746eb0cc36a4: Pull complete 
e46201569d4f: Pull complete 
e05ec73939b3: Pull complete 
a1488be2aff6: Pull complete 
a8b7dca0523d: Pull complete 
479eda4ac467: Pull complete 
6c7cbf0d184e: Pull complete 
c1e6c9fbe5e5: Pull complete 
8e788f107d54: Pull complete 
4f233ae41a29: Pull complete 
f5bd50833661: Pull complete 
2170705eade6: Pull complete 
Digest: sha256:5274dd5a23a14931662688685893de3dd6e297bd87f9f39609f9d21b50339d50
Status: Downloaded newer image for wordpress:php7.3
docker.io/library/wordpress:php7.3

四、创立数据库

1. 创立数据目录

mkdir -p /data/wordpress/{db,data}

2. 创立 mysql 数据库容器

docker run -d --name my_mysql --restart always -e MYSQL_ROOT_PASSWORD=redhat -e MYSQL_DATABASE=db_web -p 3710:3306 mysql:5.7

3. 查看 mysql 容器状态

[root@jeven ~]# docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS                  PORTS                                                  NAMES
95cb245317e3   mysql:5.7                "docker-entrypoint.s…"   38 seconds ago   Up 37 seconds           33060/tcp, 0.0.0.0:3710->3306/tcp, :::3710->3306/tcp   my_mysql

4. 近程客户端测试连贯数据库

[root@server ~]# mysql -h 192.168.3.166 -P3710 -uroot -predhat
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 2
Server version: 5.7.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db_web             |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.01 sec)

mysql> 


五、部署 wordpress

1. 创立 wordpress 容器

docker run -d --name my_wordpress --restart always --link my_mysql  -e WORDPRESS_DB_HOST=192.168.3.166:3710 -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_PASSWORD=redhat -e WORDPRESS_DB_NAME=db_web -p  8167:80  wordpress:php7.3

2. 查看 wordpress 容器状态

[root@jeven wordpress]# docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS                  PORTS                                                  NAMES
91696767911c   wordpress:php7.3         "docker-entrypoint.s…"   45 seconds ago   Up 44 seconds           0.0.0.0:8167->80/tcp, :::8167->80/tcp                  my_wordpress
95cb245317e3   mysql:5.7                "docker-entrypoint.s…"   4 minutes ago    Up 4 minutes            33060/tcp, 0.0.0.0:3710->3306/tcp, :::3710->3306/tcp   my_mysql

六、wordpress 初始配置

1. 设置中文

抉择设置中文

2. 站点初始配置

设置站点信息。

七、拜访 wordpress

1. 拜访 wordpress 前台首页

2. 进入 wordpress 后盾

正文完
 0