目 录CONTENT

文章目录

通过 Docker-Mysql搭建 Typecho

所念皆星河
2020-01-02 / 0 评论 / 0 点赞 / 47 阅读 / 4000 字

一、安装 Docker 和 Docker Compose

1. 安装 Docker

安装依赖

yum install -y yum-utils device-mapper-persistent-data lvm2

设置yum源

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

安装docker

yum install -y docker-ce

设置启动以及开机启动

systemctl enable docker
systemctl start docker
docker version

配置镜像加速器
针对Docker客户端版本大于 1.10.0 的用户
通过修改daemon配置文件/etc/docker/daemon.json来使用加速器

mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://docker.mirrors.sjtug.sjtu.edu.cn"]
}
EOF
systemctl daemon-reload
systemctl restart docker

2. 安装 Docker Compose

下载

curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

赋予执行权限

chmod +x /usr/bin/docker-compose

查看版本

docker-compose --version

二、编写docker-compose文件

创建文件

mkdir -p /home/qigx/typecho/typecho
mkdir -p /home/qigx/typecho/mysql
cd /home/qigx/typecho/

编写 vim docker-compose.yaml

version: "3.3"
services:
  typecho:
    container_name: typecho
    restart: always
    volumes:
      - /home/qigx/typecho/typecho:/data
    environment:
      - PHP_TZ=Asia/Shanghai
      - PHP_MAX_EXECUTION_TIME=600
    ports:
      - 80:80
    depends_on:
      - mysql
    networks:
      typechonetwork:
       ipv4_address: 172.188.0.3
    image: 80x86/typecho:v1.2.1-rc.2-amd64

  mysql:
    restart: always
    image: mysql:8.0.31
    container_name: mysql
    command:
      - --default-authentication-plugin=mysql_native_password
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_general_ci
      - --explicit_defaults_for_timestamp=true
    volumes:
      - /home/qigx/typecho/mysql:/var/lib/mysql
    ports:
      - 3306:3306
    environment:
      - MYSQL_ROOT_PASSWORD=123456
      - MYSQL_DATABASE=typecho
    networks:
      typechonetwork:
       ipv4_address: 172.188.0.2

networks:
  typechonetwork:
    ipam:
      config:
      - subnet: 172.188.0.0/24

启动容器

docker-compose up -d

三、输入服务器地址端口/install.php

数据库地址要填mysql容器地址

docker inspect <容器ID> | grep IPAddress

lpp5ncfk.png

0

评论区