环境:

 CentOS 7.5

 Docker 20.10.2

 Docker-Compose 1.25.5

[root@localhost ~]# cat /etc/redhat-releaseCentOS 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:      trueServer: 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 8a1c60f6docker-py version: 4.1.0CPython version: 3.7.5OpenSSL 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.ymlversion: '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的数据库名字是wordpressvolumes:    db_data: {}

说明:

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

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 driverPulling db (mysql:5.7)...5.7: Pulling from library/mysql6ec7b7d162b2: Downloading [======================================>            ]  20.64MB/27.1MBfedd960d3481: Download complete7ab947313861: Download complete64f92f19e638: Downloading [=============================================>     ]  1.278MB/1.419MB3e80b17bff96: Download complete014e976799f9: Waiting59ae84fee1b3: Waiting7d1da2a18e2e: Waiting301a28b700b9: Waiting529dc8dbeaf3: Waitingbc9d021dc13f: Waiting529dc8dbeaf3: Pull completebc9d021dc13f: Pull completeDigest: sha256:c3a567d3e3ad8b05dfce401ed08f0f6bf3f3b64cc17694979d5f2e5d78e10173Status: Downloaded newer image for mysql:5.7Pulling wordpress (wordpress:latest)...latest: Pulling from library/wordpress6ec7b7d162b2: Already existsdb606474d60c: Pull completeafb30f0cd8e0: Pull complete3bb2e8051594: Pull complete4c761b44e2cc: Pull completec2199db96575: Pull complete1b9a9381eea8: Pull complete50f0689715a3: Pull complete8a6cc018dd45: Pull complete052299cf2d76: Pull completeee83da709c88: Pull complete5b10df91e6d0: Pull completea2eb858e27d8: Pull completee6269830d5ad: Pull complete228a0fa8a95f: Pull complete91f7abe86332: Pull complete5c3d3e1e4145: Pull completee75d27a32f14: Pull complete3c632295f58e: Pull complete84352e306791: Pull completeDigest: sha256:e3a851040e7eef9c2b6dd954bfcf08b5a9847b2efbc252d4ccb1b0864225d9fcStatus: Downloaded newer image for wordpress:latestCreating my_wordpress_db_1 ... doneCreating my_wordpress_wordpress_1 ... doneAttaching to my_wordpress_db_1, my_wordpress_wordpress_1db_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 filesdb_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=45790db_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/htmldb_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: 3306db_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 eventsdb_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 messagewordpress_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 messagewordpress_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 operationswordpress_1  | [Sat Jan 09 03:56:16.984711 2021] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

`Docker网络(重要)`

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

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

[root@localhost ~]# docker network lsNETWORK ID     NAME                   DRIVER    SCOPEeb2d2ed62e6d   bridge                 bridge    local40a2cdab761b   host                   host      localaddc87976b45   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.访问

如果您喜欢本文,就请动动您的发财手为本文点赞转发评论,想获取更多运维相关内容,请记得关注我。

docker 启动mysql root用户_Docker-Compose搭建Wordpress博客系统相关推荐

  1. 巨杉Tech | 十分钟快速搭建 Wordpress 博客系统

    介绍 很多互联网应用程序开发人员第一个接触到的网站项目就是博客系统.而全球使用最广的Wordpress常常被用户用来快速搭建个人博客网站.默认情况下,Wordpress一般在后台使用MySQL关系型数 ...

  2. lnmp环境搭建 wordpress 博客系统

    安装编译工具及库文件(使用CentOS yum命令安装) yum install make apr* autoconf automake curl-devel gcc gcc-c++ zlib-dev ...

  3. 在centOS上搭建wordpress博客系统

    购买VPS后,很多人都会选择自己搭建一个网站,其中使用LAMP+wordpress可以说是最简单的建站方案,下面我就将详细介绍一下具体的建站过程.我使用的是阿里云的服务器,系统是centOS6.5,使 ...

  4. 用Docker搭建WordPress博客

    目录 用Docker搭建WordPress博客 一.WordPress简介 二.Docker安装 三.下载mysql镜像及wordpress镜像 四.启动mysql及wordpress 五.访问及初始 ...

  5. 2012 iis php mysql_Win2012 R2 IIS8.5+PHP(FastCGI)+MySQL运行环境搭建wordpress博客教程

    Win2012 R2 IIS8.5+PHP(FastCGI)+MySQL运行环境搭建教程 一.环境说明: 操作系统:Windows Server2012 R2 PHP版本:php 5.5.8 MySQ ...

  6. win2012 r2 iis php,Win2012 R2 IIS8.5+PHP(FastCGI)+MySQL运行环境搭建wordpress博客教程

    运行环境搭建教程 一.环境说明: 操作系统:Windows Server2012 R2 PHP版本:php 5.5.8 MySQL版本:MySQL5.6.15 二.相关软件下载: 1.PHP下载地址: ...

  7. 使用 Docker 搭建 WordPress 博客

    Docker Docker 是一个应用容器引擎,可以将应用运行时环境打包到一个容器中,打包后的容器可移植到任何一个 Linux 环境下运行,能有效避免繁琐的配置步骤,下面是使用 Docker 搭建 W ...

  8. 搭建WordPress博客平台,云计算技术与应用实验报告

    实验环境:阿里云云产品资源ECS服务器 题目:基于ECS部署LAMP环境 实验内容和要求: LAMP 是 Linux.Apache.MySQL和PHP的缩写,是搭建网站系统依赖的基础运行环境.本实验使 ...

  9. AWS之EC2搭建WordPress博客

    AWS之搭建WordPress博客 注意:请确定您已经成功完成LAMP架构的搭建; 1.下载并解压WordPress安装包: ①使用wget命令在WordPress官网获取最新安装包: [ec2-us ...

最新文章

  1. 【JOURNAL】《不思八九》 --和友腊八诗一首
  2. 错误处理,触发,日志使用,异常机制
  3. kfc流程管理炸薯条几秒_炸薯条成为数据科学的最后前沿
  4. leetcode130. 被围绕的区域
  5. python设计模式六大原则_学习设计模式 - 六大基本原则之迪米特法则(示例代码)...
  6. 【POJ2104】K-th Number(区间第k小的数---主席树模版题+离散化)
  7. 对比两个文件内容差异VS Visual Studio Code
  8. 银河麒麟支持php吗,银河麒麟操作系统下载
  9. 一文搞懂 UndeclaredThrowableException
  10. C++基础中的基础——平行四边形
  11. 计算机仿真和vr的区别,你真的知道AR与VR的区别吗?
  12. Bat_PNG转PDF,读取系统剪切板
  13. Filter 过滤器和 Listener 监听器,java面试必问底层
  14. struct和typedef struct彻底明白了,引用自https://www.cnblogs.com/qyaizs/articles/2039101.html
  15. CQF量化金融职业指南
  16. 数据库oracle--PL/SQL的使用-如何按f8只执行一行
  17. Ubuntu 配置WebDav服务器
  18. 电脑和手机如何将PPT转成PDF?
  19. latex 学习使用记录(插图片,插表格,插公式,插参考文献)
  20. Linux安装及管理应用程序

热门文章

  1. Docker系列之.NET Core入门(三)
  2. AddMvc 和 AddMvcCore 的区别
  3. NET主流ORM框架分析
  4. 应用程序的8个关键性能指标以及测量方法
  5. 大新闻!Magic Leap造假,HoloLens即将入华商用
  6. C# 读取硬盘信息类
  7. 使用Filezilla 与 linux远程服务器传输文件时,设置默认打开编辑器
  8. 【QGIS入门实战精品教程】4.1:QGIS栅格数据地理配准完整操作流程
  9. 【遥感物候】1983-2012年时间序列中国地区GIMMS 3g NDVI下载(已进行旋转、格式转换、投影变换和裁剪)
  10. 【ArcGIS遇上Python】ArcGIS Python批处理入门到精通实用教程目录