首页 > 其他分享 >Docker部署wordpress-6.6

Docker部署wordpress-6.6

时间:2024-07-20 12:26:59浏览次数:21  
标签:nginx 0.0 tcp 6.6 wordpress Docker root docker

目录

一. 环境准备

二. 准备对应的配置文件

三. 编写Dockerfile

四. 构建镜像

五. 配置MySQL 

六. 安装wordpress 

七. 扩展


一. 环境准备

localhost192.168.226.25

rocky_linux9.4

Docker version 27.0.3

关闭防火墙和selinux,进行时间同步。

安装docker

# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# Step 4: 更新并安装Docker-CE
sudo yum makecache
sudo yum -y install docker-ce
# Step 4: 开启Docker服务
sudo service docker start
# 验证docker
sudo docker version

下载wordpress上传至/root/目录

发行版本归档 – WordPress.org China 简体中文icon-default.png?t=N7T8https://cn.wordpress.org/download/releases/

[root@localhost ~]# ll
total 26700
-rw-r--r-- 1 root root      846 Jul 20 03:33 Dockerfile
-rw-r--r-- 1 root root      480 Jul 20 03:08 default.conf
-rw-r--r-- 1 root root      398 Jul 20 00:40 nginx.repo
-rw-r--r-- 1 root root      183 Jul 20 11:19 start.sh
-rw-r--r-- 1 root root 27323722 Jul 19 19:12 wordpress-6.6-zh_TW.zip

二. 准备对应的配置文件

nginx官方镜像源文件

[root@localhost ~]# vim /root/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

nginx的配置文件

[root@localhost ~]# vim /root/default.conf 
server {
    listen       80;
    server_name  localhost;


    location / {
        root   /usr/share/nginx/wordpress;
        index  index.php;
    }

        location ~ \.php$ {
            root          /usr/share/nginx/wordpress;
            fastcgi_pass   unix:///var/opt/remi/php80/run/php-fpm/www.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/wordpress;
    }
}

三. 编写Dockerfile

[root@localhost ~]# vim /root/Dockerfile
FROM rockylinux:9.3

LABEL \
  version="1.0" \
  description="wordpress" \
  maintainer="[email protected]"

WORKDIR /root/
EXPOSE 80 443

# 安装 Remi 仓库和 PHP
RUN yum install -y http://rpms.remirepo.net/enterprise/remi-release-9.rpm && \
    yum install -y epel-release && \
    yum install php80-php-xsl php80-php php80-php-cli php80-php-devel php80-php-gd php80-php-pdo php80-php-mysql php80-php-fpm -y
# 复制 nginx repo 配置文件并安装 nginx
COPY nginx.repo /etc/yum.repos.d/nginx.repo
RUN yum install -y nginx

# 复制 nginx 配置文件
COPY default.conf /etc/nginx/conf.d/default.conf

# 复制 WordPress 并设置适当的权限
ADD wordpress-6.6-zh_CN.tar.gz /usr/share/nginx
RUN chown -R nginx:nginx /usr/share/nginx/wordpress

# 复制启动脚本
COPY start.sh /start.sh
RUN chmod +x /start.sh

# 设置启动命令
CMD ["/start.sh"]

创建启动服务的脚本

#!/bin/bash

# 启动 PHP-FPM
/opt/remi/php80/root/usr/sbin/php-fpm
chmod 777 /var/opt/remi/php80/run/php-fpm/www.sock

# 启动 Nginx
nginx -g 'daemon off;'


四. 构建镜像

[root@localhost ~]# docker build -t wordpress:v1 .


[root@localhost ~]# docker images 
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
wordpress    v1        6f9a0e03d62a   3 minutes ago   891MB


#创建并启动容器
[root@localhost ~]# docker run -dit -P 6f9a0e03d62a
f0cd32e390ab49a671d44aee2c36c695a98ec3d3a62a7f15f48c35a4f26e90af

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS          PORTS                                                                                NAMES
f0cd32e390ab   6f9a0e03d62a   "/start.sh"   42 seconds ago   Up 42 seconds   0.0.0.0:32780->80/tcp, :::32780->80/tcp, 0.0.0.0:32781->443/tcp, :::32781->443/tcp   unruffled_poincare

浏览器访问IP+映射的端口

五. 配置MySQL 

[root@localhost ~]# docker pull mysql:8.0

[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
wordpress    v1        6f9a0e03d62a   7 hours ago   891MB
mysql        8.0       6c54cbcf775a   2 weeks ago   572MB

[root@localhost ~]# docker run --name mysql_wordpress -e MYSQL_ROOT_PASSWORD=Qaz123456+ -e MYSQL_DATABASE=wordpress -d mysql:8.0


[root@localhost ~]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                                                                                NAMES
5d8b0b70665e   mysql:8.0      "docker-entrypoint.s…"   2 minutes ago   Up 2 minutes   3306/tcp, 33060/tcp                                                                  mysql_wordpress
f0cd32e390ab   6f9a0e03d62a   "/start.sh"              7 hours ago     Up 7 hours     0.0.0.0:32780->80/tcp, :::32780->80/tcp, 0.0.0.0:32781->443/tcp, :::32781->443/tcp   unruffled_poincare

#进入mysql容器验证是否创建成功
[root@localhost ~]# docker exec -it 5d8b0b70665e mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.38 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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 |
| mysql              |
| performance_schema |
| sys                |
| wordpress          |
+--------------------+
5 rows in set (0.00 sec)

mysql> 

按住ctrl + p + q 后台运行当前容器

#查看详细信息,找到IP
[root@localhost ~]# docker inspect 5d8b0b70665e

六. 安装wordpress 

注:如果出现下图中的提示,需要进入nginx的哪个容器里去编写对应的配置

 对应步骤如下:

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                                                                NAMES
5d8b0b70665e   mysql:8.0      "docker-entrypoint.s…"   11 minutes ago   Up 11 minutes   3306/tcp, 33060/tcp                                                                  mysql_wordpress
f0cd32e390ab   6f9a0e03d62a   "/start.sh"              7 hours ago      Up 7 hours      0.0.0.0:32780->80/tcp, :::32780->80/tcp, 0.0.0.0:32781->443/tcp, :::32781->443/tcp   unruffled_poincare
[root@localhost ~]# docker exec -it f0cd32e390ab /bin/bash
[root@f0cd32e390ab /]# 

[root@f0cd32e390ab wordpress]# vi /usr/share/nginx/wordpress/wp-config.php
#将页面提示的配置代码全部粘贴并复制到该文件里

然后按ctrl + p +q 后台运行该容即可。

当配置完成后,点击执行安装程序即可。 

七. 扩展

使用--link参数。

当数据库宕机了,我们重启一个数据库,那么容器的IP就会变,因此可以使用--link参数具体操作如下:

#查看镜像ID
[root@localhost ~]# docker images 
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
wordpress    v1        6f9a0e03d62a   7 hours ago   891MB
mysql        8.0       6c54cbcf775a   2 weeks ago   572MB

#查看mysql容器名
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                                                                NAMES
5d8b0b70665e   mysql:8.0      "docker-entrypoint.s…"   32 minutes ago   Up 32 minutes   3306/tcp, 33060/tcp                                                                  mysql_wordpress
f0cd32e390ab   6f9a0e03d62a   "/start.sh"              7 hours ago      Up 7 hours      0.0.0.0:32780->80/tcp, :::32780->80/tcp, 0.0.0.0:32781->443/tcp, :::32781->443/tcp   unruffled_poincare

#重新创建一个容器,并和mysql容器名进行关联
[root@localhost ~]# docker run -dit -P --link=mysql_wordpress 6f9a0e03d62a
3ea2e9862b9a8b91c8b84e552665968a5ca6c10326ab367bd2bf602639638928


[root@localhost ~]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED              STATUS              PORTS                                                                                NAMES
3ea2e9862b9a   6f9a0e03d62a   "/start.sh"              About a minute ago   Up About a minute   0.0.0.0:32782->80/tcp, :::32782->80/tcp, 0.0.0.0:32783->443/tcp, :::32783->443/tcp   bold_mclaren
5d8b0b70665e   mysql:8.0      "docker-entrypoint.s…"   34 minutes ago       Up 34 minutes       3306/tcp, 33060/tcp                                                                  mysql_wordpress
f0cd32e390ab   6f9a0e03d62a   "/start.sh"              7 hours ago          Up 7 hours          0.0.0.0:32780->80/tcp, :::32780->80/tcp, 0.0.0.0:32781->443/tcp, :::32781->443/tcp   unruffled_poincare

查看到了刚创建的容器端口,现在浏览器进行访问IP+映射出来的端口、

这数据库宕了,可以重新起一个数据库容器,但是要求重新起的数据库容器名要和这里填写的mysql_wordpress一致。 

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                                                                NAMES
3ea2e9862b9a   6f9a0e03d62a   "/start.sh"              9 minutes ago    Up 9 minutes    0.0.0.0:32782->80/tcp, :::32782->80/tcp, 0.0.0.0:32783->443/tcp, :::32783->443/tcp   bold_mclaren
5d8b0b70665e   mysql:8.0      "docker-entrypoint.s…"   42 minutes ago   Up 42 minutes   3306/tcp, 33060/tcp                                                                  mysql_wordpress
f0cd32e390ab   6f9a0e03d62a   "/start.sh"              8 hours ago      Up 8 hours      0.0.0.0:32780->80/tcp, :::32780->80/tcp, 0.0.0.0:32781->443/tcp, :::32781->443/tcp   unruffled_poincare
[root@localhost ~]# docker exec -it 3ea2e9862b9a /bin/bash
[root@3ea2e9862b9a /]# vi /usr/share/nginx/wordpress/wp-config.php
#将页面提示的配置代码全部粘贴并复制到该文件里

然后按ctrl + p +q 后台运行该容即可。

 

标签:nginx,0.0,tcp,6.6,wordpress,Docker,root,docker
From: https://blog.csdn.net/Lzcsfg/article/details/140565989

相关文章

  • docker 创建 oracle 11g
    参考【DB宝11】在Docker中只需2步即可拥有Oracle11g企业版环境(11.2.0.3)拉取镜像#从Dockerhub下载,网络不好时,一般比较慢dockerpulllhrbest/oracle_11g_ee_lhr_11.2.0.3:1.0#可以选择从阿里云下载dockerpullregistry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_11g_ee_......
  • maven项目容器化运行之2-maven中使用docker插件调用远程docker构建服务并在1Panel中运
    一.背景    公司主机管理小组的同事期望我们开发的maven项目能够在1Panel管理的docker容器部署。上一篇写了先开放1Panel中docker镜像构建能力maven项目容器化运行之1-基于1Panel软件将docker镜像构建能力分享给局域网-CSDN博客。这一篇就是演示maven工程的镜像构建、......
  • Docker群晖docker查询注册表失败
    解决群晖NASUI(或SSH中)的dockerpull错误(无法拉取,注册表错误)朗读全文Yourbrowserdoesnotsupporttheaudioelement.有什么用errorpullingimageconfiguration:Get"https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/...dialtcp......
  • Docker搭建BT-Tracker服务器贡献BT网络Tracker节点
    为畅享BT下载体验,(BT下载或做种)请添加Tracker:http://tracker.carlzeng.top:6969/announce长期自主自觉维护朗读全文Yourbrowserdoesnotsupporttheaudioelement.有什么用搭建BTTracker服务器,自建公共的BT网络Tracker节点为畅享更快BT下载体验,请给添加本站BTTrac......
  • docker创建基础镜像
    1.编写dockerfileFROMcentos:7.9.2009#替换默认的yum源RUNrm-f/etc/yum.repos.d/*\&&curl-o/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-7.repo\&&yummakecacheRUNyum-yupdate&&\......
  • docker安装
    docker三大核心概念镜像:images,即软件,里面包含了一个微型操作系统+核心代码程序+依赖库环境--》镜像文件越小越好dockerload导入镜像,dockerload-imysql-5-7-41.tardockersave导出镜像如dockersave-omysql-5-7-41.tarmysql:5.7.41仓库:存放镜像的地方容器:运行镜......
  • Ubuntu 20.04 ARM64安装Docker
    Ubuntu20.04ARM64安装Docker内容参考:https://blog.csdn.net/qq_34253926/article/details/121629068查看系统版本hostnamectl可以看到,我的版本是Ubuntu20.04,我的内核是arm64更新aptsudoapt-getupdate安装基本软件sudoapt-getinstallcurlwgetapt-transport-ht......
  • docker-compose教程(安装,使用, 快速入门)
    docker-compose教程(安装,使用,快速入门)一、docker-compose介绍DockerCompose是一个用来定义和运行多个复杂应用的Docker编排工具。例如,一个使用Docker容器的微服务项目,通常由多个容器应用组成。那么部署时如何快速启动各个微服务呢,一个个手动启动?假如有上百个微服务呢,显然不现......
  • Linux环境离线安装docker&docker-compose(包含一键安装脚本和一键安装包)
    一、docker离线安装1、下载docker离线安装包下载最新版本的docker(或者选择自己想要安装的版本)到本地。1)docker下载地址:Docker版本获取备注:此地址自2024年7月无法访问下载docker版本,小编已经将可以使用的docker、docker-compose版本整理在百度网盘中如有需要可以自行获取......
  • dockerfile来快速部署一个jsp服务
    1.创建一个jsp服务需要的dockfilevimjsp_dockerfile#UsetheofficialUbuntu 20.04 baseimageFROMubuntu:20.04 #SetenvironmentvariablesENVDEBIAN_FRONTEND=noninteractive #InstallnecessarypackagesRUNapt-getupdate&&\    apt-getinsta......