用Docker-Compose一分钟搭建Wordpress博客系统

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 用Docker-Compose一分钟搭建Wordpress博客系统

环境:


CentOS 7.5


Docker 20.10.2


Docker-Compose 1.25.5

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@localhost ~]# docker version            # Docker版本
Client: Docker Engine - Community
 Version:           20.10.2
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        2291f61
 Built:             Mon Dec 28 16:17:48 2020
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
Server: Docker Engine - Community
 Engine:
  Version:          20.10.2
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       8891c58
  Built:            Mon Dec 28 16:16:13 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.3
  GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc:
  Version:          1.0.0-rc92
  GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@localhost ~]# docker-compose version       # Docker-compose版本
docker-compose version 1.25.5, build 8a1c60f6
docker-py version: 4.1.0
CPython version: 3.7.5
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

参考:


 Docker-Compose官方搭建Wordpress教程:https://docs.docker.com/compose/wordpress/


1.下载项目(docker-compose.yml)

[root@localhost ~]# cd /home/
[root@localhost home]# mkdir my_wordpress
[root@localhost home]# cd my_wordpress/
[root@localhost my_wordpress]# vim docker-compose.yml
version: '3.3'           #compose文件版本
services:
   db:                   # 服务1:db
     image: mysql:5.7    # 使用镜像 mysql:5.7版本
     volumes:
       - db_data:/var/lib/mysql   # 数据持久化
     restart: always     # 容器服务宕机后总是重启
     environment:        # 环境配置
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress
   wordpress:          # 服务2:wordpress
     depends_on:       # wordpress服务启动时依赖db服务,所以会自动先启动db服务
       - db
     image: wordpress:latest    # 使用镜像 wordpress:latest最新版
     ports:
       - "8000:80"          #端口映射8000:80
     restart: always
     environment:        # 环境
       WORDPRESS_DB_HOST: db:3306     # wordpress连接db的3306端口
       WORDPRESS_DB_USER: wordpress    # wordpress的数据库用户为wordpress
       WORDPRESS_DB_PASSWORD: wordpress   # wordpress的数据库密码是wordpress
       WORDPRESS_DB_NAME: wordpress    # wordpress的数据库名字是wordpress
volumes:
    db_data: {}

说明:


 可以看到上面的docker-compose.yml文件中第一行为version:'3.3',这个是compose文件的版本,它是与docker引擎的版本相对应的,并且向下兼容。

1.png

2.启动项目


注意:大部分的compose命令都需要到docker-compose.yml文件所在的目录下才能执行。

前台启动项目:  docker-compose up


 **后台执行该服务可以加上 *-d* 参数:** docker-compose up -d


 指定yml文件启动:docker-compose -f 【yml文件绝对路径】 up / -d

[root@localhost my_wordpress]# docker-compose up  -d  # 后台运行项目
Creating network "my_wordpress_default" with the default driver   
  -----》# 为wordpress项目创建my_wordpress_default网络
Creating volume "my_wordpress_db_data" with default driver
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
6ec7b7d162b2: Downloading [======================================>            ]  20.64MB/27.1MB
fedd960d3481: Download complete
7ab947313861: Download complete
64f92f19e638: Downloading [=============================================>     ]  1.278MB/1.419MB
3e80b17bff96: Download complete
014e976799f9: Waiting
59ae84fee1b3: Waiting
7d1da2a18e2e: Waiting
301a28b700b9: Waiting
529dc8dbeaf3: Waiting
bc9d021dc13f: Waiting
529dc8dbeaf3: Pull complete
bc9d021dc13f: Pull complete
Digest: sha256:c3a567d3e3ad8b05dfce401ed08f0f6bf3f3b64cc17694979d5f2e5d78e10173
Status: Downloaded newer image for mysql:5.7
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
6ec7b7d162b2: Already exists
db606474d60c: Pull complete
afb30f0cd8e0: Pull complete
3bb2e8051594: Pull complete
4c761b44e2cc: Pull complete
c2199db96575: Pull complete
1b9a9381eea8: Pull complete
50f0689715a3: Pull complete
8a6cc018dd45: Pull complete
052299cf2d76: Pull complete
ee83da709c88: Pull complete
5b10df91e6d0: Pull complete
a2eb858e27d8: Pull complete
e6269830d5ad: Pull complete
228a0fa8a95f: Pull complete
91f7abe86332: Pull complete
5c3d3e1e4145: Pull complete
e75d27a32f14: Pull complete
3c632295f58e: Pull complete
84352e306791: Pull complete
Digest: sha256:e3a851040e7eef9c2b6dd954bfcf08b5a9847b2efbc252d4ccb1b0864225d9fc
Status: Downloaded newer image for wordpress:latest
Creating my_wordpress_db_1 ... done
Creating my_wordpress_wordpress_1 ... done
Attaching to my_wordpress_db_1, my_wordpress_wordpress_1
db_1         | 2021-01-09 03:56:06+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.32-1debian10 started.
db_1         | 2021-01-09 03:56:06+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1         | 2021-01-09 03:56:06+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.32-1debian10 started.
db_1         | 2021-01-09 03:56:06+00:00 [Note] [Entrypoint]: Initializing database files
db_1         | 2021-01-09T03:56:06.498622Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1         | 2021-01-09T03:56:06.956978Z 0 [Warning] InnoDB: New log files created, LSN=45790
db_1         | 2021-01-09T03:56:06.992692Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
db_1         | 2021-01-09T03:56:07.053810Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 99ff1af4-522e-11eb-a33c-0242ac130002.
db_1         | 2021-01-09T03:56:07.054442Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
wordpress_1  | WordPress not found in /var/www/html - copying now...
wordpress_1  | Complete! WordPress has been successfully copied to /var/www/html
db_1         | 2021-01-09T03:56:07.578842Z 0 [Warning] CA certificate ca.pem is self signed.
wordpress_1  | [09-Jan-2021 03:56:07 UTC] PHP Warning:  mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
...
db_1         | 2021-01-09T03:56:16.546749Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
db_1         | 2021-01-09T03:56:16.547255Z 0 [Warning] CA certificate ca.pem is self signed.
db_1         | 2021-01-09T03:56:16.547310Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
db_1         | 2021-01-09T03:56:16.547780Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1         | 2021-01-09T03:56:16.547866Z 0 [Note] IPv6 is available.
db_1         | 2021-01-09T03:56:16.547878Z 0 [Note]   - '::' resolves to '::';
db_1         | 2021-01-09T03:56:16.547892Z 0 [Note] Server socket created on IP: '::'.
db_1         | 2021-01-09T03:56:16.548648Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1         | 2021-01-09T03:56:16.555145Z 0 [Note] Event Scheduler: Loaded 0 events
db_1         | 2021-01-09T03:56:16.555312Z 0 [Note] mysqld: ready for connections.
db_1         | Version: '5.7.32'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
wordpress_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message
wordpress_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message
wordpress_1  | [Sat Jan 09 03:56:16.984658 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.14 configured -- resuming normal operations
wordpress_1  | [Sat Jan 09 03:56:16.984711 2021] [core:notice] [pid 1] AH00094: Command lin


2.png

Docker网络(重要)


 可以看到在使用docker-compose管理项目的时候,docker-compose会自动给我们创建一个项目网络,这是docker-compose的网络默认规则,创建的项目网络可以方便我们管理维护项目,同一个项目的所有服务可以直接互相通过服务名访问!!!


 这样的一个好处是:开发不需要在配置中写死某个服务的IP地址,只需要写服务名即可,当该服务异常挂掉,同一个服务重启后IP可能会不同,如果写死的话就得去更改,很麻烦。所以这就是docker-compose默认创建网络提供的便利性。

[root@localhost ~]# docker network ls
NETWORK ID     NAME                   DRIVER    SCOPE
eb2d2ed62e6d   bridge                 bridge    local
40a2cdab761b   host                   host      local
addc87976b45   my_wordpress_default   bridge    local       #项目网络
446393a43e7b   none                   null      local
[root@localhost ~]# docker network inspect my_wordpress_default    #查看项目网络详情
[
    {
        "Name": "my_wordpress_default",
        "Id": "addc87976b4535cdb24c84a00afc9744b5951a520e7230bc8ef76189ea06bf05",
        "Created": "2021-01-09T11:55:20.242710185+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.19.0.0/16",
                    "Gateway": "172.19.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "c95da3fa0f6c42a564d99b35f70e5c51c5a1163ab53b9a6ae305f98d6b2b6f9f": {
                "Name": "my_wordpress_db_1",
                "EndpointID": "e1a66aec2e36fb74d0d75af69ff6c74c20c06508bfe2d8c34384d45062007c25",
                "MacAddress": "02:42:ac:13:00:02",
                "IPv4Address": "172.19.0.2/16",
                "IPv6Address": ""
            },
            "cccd067d18e46beb27a345721148569464ad618c1cfd99357fe4b80d75e7ff27": {
                "Name": "my_wordpress_wordpress_1",
                "EndpointID": "f238817ce5358d7b57a1668ea9ddda40c88a227c2c1d762fa553e38fd22d7e2b",
                "MacAddress": "02:42:ac:13:00:03",
                "IPv4Address": "172.19.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "my_wordpress",
            "com.docker.compose.version": "1.25.5"
        }
    }
]

3.png

3.访问

4.png5.png6.png

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
打赏
0
0
0
0
12
分享
相关文章
在Ubuntu系统的Docker上安装MySQL的方法
以上的步骤就是在Ubuntu系统的Docker上安装MySQL的详细方法,希望对你有所帮助!
91 12
zabbix7.0.9安装-以宝塔安装形式-非docker容器安装方法-系统采用AlmaLinux9系统-最佳匹配操作系统提供稳定运行环境-安装教程完整版本-优雅草卓伊凡
zabbix7.0.9安装-以宝塔安装形式-非docker容器安装方法-系统采用AlmaLinux9系统-最佳匹配操作系统提供稳定运行环境-安装教程完整版本-优雅草卓伊凡
136 30
零基础搭建WordPress博客全流程指南!
本指南详细介绍如何使用宝塔面板与WordPress搭建个人博客。宝塔面板提供可视化操作,简化服务器管理;WordPress拥有丰富的主题和插件生态,支持快速建站。教程涵盖准备阶段(服务器、域名、面板安装)、环境配置、站点创建、SSL证书申请、WordPress一键部署及网站配置等步骤,并推荐必备插件提升安全性和性能。零基础用户也可轻松上手,适合日均5000PV以下的博客需求,扩展性强,助你开启创作之旅。
107 7
如何在Ubuntu 20.04系统中安装Docker
安装 Docker 引擎的步骤如下:首先更新系统包索引 (`sudo apt update`),安装必要依赖包 (`apt-transport-https` 等),添加 Docker 官方 GPG 密钥及 APT 仓库。接着再次更新包索引并安装 Docker 引擎及相关工具 (`docker-ce` 等)。最后启动 Docker 服务并设置开机自启,通过 `docker --version` 和运行测试容器 (`sudo docker run hello-world`) 验证安装是否成功。
347 0
Docker容器环境中服务发现与负载均衡的技术与方法,涵盖环境变量、DNS、集中式服务发现系统等方式
本文探讨了Docker容器环境中服务发现与负载均衡的技术与方法,涵盖环境变量、DNS、集中式服务发现系统等方式,以及软件负载均衡器、云服务负载均衡、容器编排工具等实现手段,强调两者结合的重要性及面临挑战的应对措施。
187 3
|
5月前
WordPress小白傻瓜式一键搭建博客个人网站详细教程
用宝塔功能来一键搭建WordPress博客网站。 最详细教程! 整个过程简单、易用,即使是零基础用户也能轻松上手。
582 1
Docker-compose 编排lnmp(dockerfile) 完成Wordpress
通过使用Docker Compose,我们可以轻松编排LNMP环境并部署WordPress。本文详细介绍了各组件的Dockerfile和配置文件编写,并通过docker-compose.yml文件实现了整个环境的自动化部署。这种方法不仅简化了部署过程,还提高了环境的可移植性和一致性。希望本文能帮助你更好地理解和使用Docker Compose来管理和部署复杂的应用程序。
339 4
centos系统清理docker日志文件
通过以上方法,可以有效清理和管理CentOS系统中的Docker日志文件,防止日志文件占用过多磁盘空间。选择合适的方法取决于具体的应用场景和需求,可以结合手动清理、logrotate和调整日志驱动等多种方式,确保系统的高效运行。
466 2
Docker部署MaxKB详细步骤(window系统)
这篇文章详细介绍了如何在Windows系统上使用Docker部署MaxKB,并提供了从安装Docker到运行MaxKB容器的详细步骤,以及如何通过浏览器访问和配置MaxKB来使用ollama和llama3模型进行问答。
2017 1
Docker部署MaxKB详细步骤(window系统)
想要轻松地搭建一个即开即用的WordPress博客吗?借助宝塔面板镜像+阿里云ECS,迅速拥有自己的个人博客
拥有个人博客是每位程序员的梦想,但对服务器不熟悉的初学者而言,搭建博客颇具挑战。本文介绍利用阿里云市场的宝塔面板镜像与ECS云服务器,轻松搭建WordPress博客的方法,让您快速拥有专属博客空间。通过简单的操作步骤,即使是新手也能轻松上手,实现从零到有的博客搭建过程。
406 3