Docker搭建Typecho博客

首页 / 学习 / 正文

EZ4ENCE

Docker搭建Typecho博客

搭建方式

搭建

apt install docker.io docker-compose -y  # 一键在服务器上安装docker和dockers-compose
apt update -y  # 升级packages
apt install wget curl sudo vim git  # Debian系统比较干净,安装常用的软件

创建一下安装的目录

mkdir -p /root/data/docker_data/typecho
cd /root/data/docker_data/typecho

创建文件

mysql

cd /root/data/docker_data/typecho
nano mysql.env

在mysql.env填入下面内容

MYSQL_ROOT_PASSWORD=root_pass
MYSQL_DATABASE=typecho
MYSQL_USER=username
MYSQL_PASSWORD=password

php-fpm

创建php文件

cd /root/data/docker_data/typecho

mkdir php

cd php

nano Dockerfile

在php中填入下面内容

FROM php:7.3.29-fpm
RUN apt-get update \
    && docker-php-ext-install pdo_mysql \
    && echo "output_buffering = 4096" > /usr/local/etc/php/conf.d/php.ini \
    && echo "date.timezone = PRC" >> /usr/local/etc/php/conf.d/php.ini

nginx

创建nginx文件

cd /root/data/docker_data/typecho

mkdir nginx

cd nginx

nano default.conf

在nginx文件填入下面内容

server {
    listen 80 default_server;
    root /var/www/html;
    index index.php;

    access_log /var/log/nginx/typecho_access.log main;
    if (!-e $request_filename) {
        rewrite ^(.*)$ /index.php$1 last;
    }
    location / {
        index index.html index.htm index.php;

        if (!-e $request_filename) {
            rewrite . /index.php last;
        }
    }

    location ~ \.php(.*)$ {
        fastcgi_pass   php:9000;
        fastcgi_index  index.php;
        fastcgi_param  PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

下载源码

cd /root/data/docker_data/typecho/typecho

wget https://github.com/typecho/typecho/releases/download/v1.2.0/typecho.zip

apt install zip -y 

unzip typecho.zip

创建docker-compose文件

cd /root/data/docker_data/typecho

nano docker-compose.yml

填写docker-compose.yml内容

version: "3"

services:
  nginx:
    image: nginx
    ports:
      - "80:80"    # 左边可以改成任意没使用的端口
    restart: always
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - ./typecho:/var/www/html
      - ./nginx:/etc/nginx/conf.d
      - ./logs:/var/log/nginx
    depends_on:
      - php
    networks:
      - web

  php:
    build: php
    restart: always
    expose:
      - "9000"       # 不暴露公网,故没有写9000:9000
    volumes:
      - ./typecho:/var/www/html
    environment:
      - TZ=Asia/Shanghai
    depends_on:
      - mysql
    networks:
      - web

  mysql:
    image: mysql:5.7
    restart: always
    environment:
      - TZ=Asia/Shanghai
    expose:
      - "3306"  # 不暴露公网,故没有写3306:3306
    volumes:
      - ./mysql/data:/var/lib/mysql
      - ./mysql/logs:/var/log/mysql
      - ./mysql/conf:/etc/mysql/conf.d
    env_file:
      - mysql.env
    networks:
      - web

networks:
  web:

使用教程-google一下

无标签
文章目录