使用docker-compose 搭建WordPress博客

大家好,今天给大家分享一下使用docker-compose 搭建WordPress博客首先,请跟着我的上一篇博客安装docker-compose的环境就是这个查看版本这就是没问题的随便进入一个目录新建一个目录进入这个目录编写docker-compose.yml 文件保存退出启动它会自动的下载需要的镜像的这个时间可能会比较长这一推都是他后台运行的日志http://192.168.1.12:8000浏览器访问,8000是dockerfile文件里写明的我们在浏览器上就可以看见WordP
摘要由CSDN通过智能技术生成

大家好,今天给大家分享一下使用docker-compose 搭建WordPress博客

首先,请跟着我的上一篇博客安装docker-compose的环境

就是这个

查看版本

这就是没问题的

[root@localhost composetest]# docker-compose version
docker-compose version 1.29.1, build c34c88b2
docker-py version: 5.0.0
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019
[root@localhost composetest]# 

随便进入一个目录

[root@localhost composetest]# cd /home/

新建一个目录

[root@localhost home]# mkdir my_wordpree/

进入这个目录

[root@localhost home]# cd my_wordpree/

编写docker-compose.yml 文件

[root@localhost my_wordpree]# vim docker-compose.yml
version: "3.9"
    
services:
  db:
    image: 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:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
      - wordpress_data:/var/www/html
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
volumes:
  db_data: {
   }
  wordpress_data: {
   }

保存退出

启动

[root@localhost my_wordpree]# docker-compose up      

它会自动的下载需要的镜像的
这个时间可能会比较长

Creating network "my_wordpree_default" with the default driver
Creating volume "my_wordpree_db_data" with default driver
Creating volume "my_wordpree_wordpress_data" with default driver
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
72a69066d2fe: Pull complete
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
0ceb82207cd7: Pull complete
37f2405cae96: Pull completeMB/108.6MBB3: Downloading [========>                                          ]     9
70deed891d42: Download complete^CGracefully stopping... (press Ctrl+C again to force)
[root@localhost my_wordpree]# docker-compose up
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
72a69066d2fe: Pull complete
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
0ceb82207cd7: Pull complete
37f2405cae96: Pull complete
e2482e017e53: Pull complete
70deed891d42: Pull complete
Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
Status: Downloaded newer image for mysql:5.7
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
a2abf6c4d29d: Already exists
c5608244554d: Pull complete
2d07066487a0: Pull complete
1b6dfaf1958c: Pull complete
32c5e6a60073: Pull complete
90cf855b27cc: Pull complete
8b0f1068c586: Pull complete
5355461305e8: Pull complete
ad1eec592342: Pull complete
e03fbc76cb78: Pull complete
1f5796e48b39: Pull complete
72fbe8e1d4e7: Pull complete
96edece66175: Pull complete
5f46f0743de2: Pull complete
c9f9671a5e1f: Pull complete
3f543dcd35b1: Pull complete
c88e21a0c2a0: Pull complete
964b4457a910: Pull complete
0d55fb9a64ef: Pull complete
fb009ff7c567: Pull complete
4f058a67a50d: Pull complete
Digest: sha256:fc33b796b04162a0db2e9ea9b4c361a07058b21597b1317ad9ab3ea4593de241
Status: Downloaded newer image for wordpress:latest
Creating my_wordpree_db_1 ... done
Creating my_wordpree_wordpress_1 ... done
Attaching to my_wordpree_db_1, my_wordpree_wordpress_1

这一推都是他后台运行的日志

db_1         | 2022-06-02 08:22:56+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
db_1         | 2022-06-02 08:22:57+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1         | 2022-06-02 08:22:57+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
db_1         | 2022-06-02 08:22:57+00:00 [Note] [Entrypoint]: Initializing database files
db_1         | 2022-06-02T08:22:57.622164Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1         | 2022-06-02T08:23:33.110360Z 0 [Warning] InnoDB: New log files created, LSN=45790
db_1         | 2022-06-02T08:23:33.149546Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
db_1         | 2022-06-02T08:23:33.205921Z 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: 4a825bda-e24d-11ec-96ba-0242ac130002.
db_1         | 2022-06-02T08:23:33.206762Z 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
wordpress_1  | No 'wp-config.php' found in /var/www/html, but 'WORDPRESS_...' variables supplied; copying 'wp-config-docker.php' (WORDPRESS_DB_HOST WORDPRESS_DB_NAME WORDPRESS_DB_PASSWORD WORDPRESS_DB_USER)
db_1         | 2022-06-02T08:23:34.266129Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
db_1         | 2022-06-02T08:23:34.266148Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
db_1         | 2022-06-02T08:23:34.266559Z 0 [Warning] CA certificate ca.pem is self signed.
db_1         | 2022-06-02T08:23:34.424496Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
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  | [Thu Jun 02 08:23:37.160075 2022] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.51 (Debian) PHP/7.4.27 configured -- resuming normal operations
wordpress_1  | [Thu Jun 02 08:23:37.160135 2022] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
db_1         | 2022-06-02 08:23:41+00:00 [Note] [Entrypoint]: Database files initialized
db_1         | 2022-06-02 08:23:41+00:00 [Note] [Entrypoint]: Starting temporary server
db_1         | 2022-06-02 08:23:41+00:00 [Note] [Entrypoint]: Waiting for server startup
db_1         | 2022-06-02T08:23:46.760440Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1         | 2022-06-02T08:23:46.762338Z 0 [Note] mysqld (mysqld 5.7.36) starting as process 76 ...
db_1         | 2022-06-02T08:23:46.764755Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1         | 2022-06-02T08:23:46.764767Z 0 
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
Docker Compose 是 Docker 官方推出的工具,用于定义和运行多个 Docker 容器的应用。它可以通过一个 YAML 文件来配置应用程序的服务,然后使用一个命令即可创建和启动所有配置的服务。 本文将介绍如何使用 Docker Compose 搭建 WordPress。 1. 安装 DockerDocker Compose 在开始之前,需要先安装 DockerDocker Compose。具体安装方法可以参考 DockerDocker Compose 的官方文档。 2. 创建 docker-compose.yml 文件 在本地创建一个新的目录,并创建一个名为 docker-compose.yml 的文件。在该文件中,定义 WordPressMySQL 服务的配置。具体配置如下: ```yaml version: '3.3' services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: example wordpress: depends_on: - db image: wordpress:latest ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: root WORDPRESS_DB_PASSWORD: example WORDPRESS_DB_NAME: wordpress volumes: db_data: ``` 以上配置创建了两个服务:一个 MySQL 服务(db),一个 WordPress 服务(wordpress)。其中,MySQL 服务使用MySQL 5.7 镜像,并挂载了一个数据卷 db_data,用于持久化数据。WordPress 服务使用了最新的 WordPress 镜像,并将容器的 80 端口映射到本地的 8000 端口。WordPress 服务还依赖于 MySQL 服务,因此在服务定义中使用了 depends_on 字段。最后,定义了 MySQLWordPress 服务的环境变量,用于配置数据库连接和认证信息。 3. 启动服务 在终端中,进入到 docker-compose.yml 文件所在的目录,并运行以下命令启动服务: ``` docker-compose up -d ``` 该命令将创建并启动 MySQLWordPress 服务。其中,-d 参数用于将服务放在后台运行。 4. 访问 WordPress 在浏览器中访问 http://localhost:8000,即可看到 WordPress 的安装页面。按照页面提示,输入数据库连接信息和管理员账号信息,即可完成 WordPress 的安装。 5. 停止服务 如果需要停止服务,可以在终端中进入到 docker-compose.yml 文件所在的目录,并运行以下命令: ``` docker-compose down ``` 该命令将停止并删除所有服务容器。同时,如果之前创建了数据卷,也会将其删除。如果需要保留数据卷,可以使用以下命令: ``` docker-compose down --volumes ``` 以上就是使用 Docker Compose 搭建 WordPress 的完整步骤。通过使用 Docker Compose,我们可以非常方便地创建和管理多个 Docker 容器,并将它们组合成一个完整的应用程序。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

思诚代码块

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值