利用Docker一键安装WordPress

同样,这也是社团任务…

这次,我选用Centos8来进行

配置Docker及系统环境

首先,安装Docker

推荐使用自动脚本安装(省事,快捷),通过mirror选项更换国内源

curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh --mirror Aliyun

启用Docker

systemctl enable docker
systemctl start docker

开启v4转发(不开就没法关防火墙…容器也可能连不了外网)

vi /etc/sysctl.conf
#在其中添加
net.ipv4.ip_forward=1
#重启网络生效
systemctl restart network

关闭防火墙及SELinux(也是因为懒)

#停止firewalld服务
systemctl stop firewalld
#禁止firewalld自起
systemctl disable firewalld
#临时关闭SELinux
setenforce 0
#永久关闭SELinux
vi /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled

使用YAML一键构建

建立一个wordpress.yml文件

vi wordpress.yml

在其中键入(3.1版语法)

version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 80:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpressuser
      WORDPRESS_DB_PASSWORD: wordpresspass
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wordpress:/var/www/html

  db:
    image: mariadb
    restart: always
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpressuser
      MYSQL_PASSWORD: wordpresspass
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

volumes:
  wordpress:
  db:

以上根据官方文档修改

一键安装

docker stack deploy -c stack.yml wordpress

安装完成后可通过http://swarm-iphttp://localhost, or http://host-ip访问

附1:

我是使用DaoCloud一键构建的,但由于平台只支持YAML 2.0,因此,我修改了上方代码,形成下方代码(适用于DaoCloud,别的不清楚)

wordpress:
  image: wordpress
  ports:
  - 80:80
  environment:
  - WORDPRESS_DB_HOST=db
  - WORDPRESS_DB_USER=wordpress
  - WORDPRESS_DB_PASSWORD=password
  - WORDPRESS_DB_NAME=wordpress
  restart: always
  links:
  - db
  volumes:
  - wordpress:/var/www/html
db:
  image: mariadb
  restart: always
  environment:
  - MYSQL_DATABASE=wordpress
  - MYSQL_USER=wordpress
  - MYSQL_PASSWORD=password
  - MYSQL_RANDOM_ROOT_PASSWORD='1'
  volumes:
  - db:/var/lib/mysql

附2:

还顺便研究了下Minecraft的Docker一键部署(同样2.0版)

minecraft:
  image: index.docker.io/itzg/minecraft-server:20190824  //有新版本自行更换
  privileged: false
  restart: always
  ports:
  - 25575:25575  //推荐更改此端口,这个为控制端口
  - 25565:25565
  volumes:
  - /data:/data
  environment:
  - EULA=TRUE  //不同意不能部署

详见 https://hub.docker.com/r/itzg/minecraft-server

发表评论