TypechoJoeTheme

运维茶馆

统计
登录
用户名
密码

使用docker运行typecho博客

少延博主
2022-01-06
/
0 评论
/
239 阅读
/
115 个字
/
百度已收录
01/06
本文最后更新于2022年01月26日,已超过111天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

现成的镜像,可以使用https://hub.docker.com/r/80x86/typecho

这里使用自定义构建镜像。这样可以方便选择特定的php版本

dockerfile

dockerfile文件

FROM php:7.3-fpm-alpine3.11
ADD repositories /etc/apk/repositories
ADD default.conf /
ADD php.ini /
ADD run.sh /
ADD build/ /var/www/html/typecho
RUN apk update && apk add nginx && \
    apk add m4 autoconf make gcc g++ linux-headers && \
    docker-php-ext-install pdo_mysql opcache mysqli && \
    mkdir /run/nginx && \
    mv /default.conf /etc/nginx/conf.d && \
    mv /php.ini /usr/local/etc/php/ && \
    touch /run/nginx/nginx.pid && \
    chmod 755 /run.sh && \
    apk del m4 autoconf make gcc g++ linux-headers &&\
    chown www-data:www-data -R /var/www/html

EXPOSE 80
EXPOSE 9000

ENTRYPOINT ["/run.sh"]

dockerfile涉及的目录和文件

$ tree -L 1
.
|-- build
|-- default.conf
|-- dockerfile
|-- php.ini
|-- repositories
`-- run.sh

1 directory, 5 files

build目录

build目录是下载 typecho 后解压出来的。

default.conf

server {
  listen   80; ## listen for ipv4; this line is default and implied
  server_name localhost;
  root /var/www/html/typecho;
  index index.php index.html index.htm;


  location ~ .*\.php(\/.*)*$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    try_files $uri /index.php =404;
    #fastcgi_pass unix:/var/run/php7-fpm.sock;
    fastcgi_pass 127.0.0.1:9000;
    # Mitigate https://httpoxy.org/ vulnerabilities
          fastcgi_param HTTP_PROXY "";
    fastcgi_index index.php;
    include fastcgi.conf;
    fastcgi_connect_timeout 300;
    fastcgi_read_timeout 600;
    fastcgi_send_timeout 300;
    fastcgi_buffer_size 128k;
    fastcgi_buffers   4 128k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
  }

    #unless the request is for a valid file (image, js, css, etc.), send to bootstrap
    if (!-e $request_filename)
    {
        rewrite ^(.*)$ /index.php$1 last;
        break;
    }

    location / {
          index  index.php
          try_files $uri $uri/ /index.php?$query_string;
    }

  location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|ttf|ttc|otf|eot|woff)$ {
    try_files $uri /index.php?$query_string;
    expires max;
    access_log off;
    log_not_found off;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
  }

  location ~* \.(?:css|js)$ {
    try_files $uri /index.php?$query_string;
    expires 1y;
    add_header Cache-Control "public";
  }

  # deny access to . files, for security
  location ~* (?:^|/)\. {
    access_log off;
    log_not_found off;
    deny all;
  }

  location ~* (?:\.(?:bak|config|db|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$ {
    deny all;
    access_log off;
    log_not_found off;
  }

}

php.ini

output_buffering =on

repositories

https://mirrors.aliyun.com/alpine/v3.11/main/
https://mirrors.aliyun.com/alpine/v3.11/community/

run.sh

#!/bin/sh

php-fpm -D
nginx -g 'daemon off;'

构建镜像

docker build -t typecho-php-nginx:v3 .

启动MySQL服务

docker run --name mysql57 -v /data/db/mysql57:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 -d mysql:5.7

运行typecho

docker run --name blog-prod -v /data/app/typecho/:/data -p 8800:80 -d typecho-php-nginx:v3

访问进行安装博客


映射卷处理

usr放到映射卷/data下面

$  docker exec -it blog-prod sh
/var/www/html # ls
typecho
/var/www/html # cd typecho/
/var/www/html/typecho # 
/var/www/html/typecho # mv usr/* /data/
/var/www/html/typecho # rm -rf usr
/var/www/html/typecho # ln -s /data /var/www/html/typecho/usr
/var/www/html/typecho # mv config.inc.php /data/
/var/www/html/typecho # ln -s /data/config.inc.php /var/www/html/typecho/config.inc.php
/var/www/html/typecho # 

落盘的本地磁盘的文件如下,可以不用进容器,即可更新配置和主题。

$ ls /data/app/typecho/
config.inc.php  plugins  themes  uploads

赞(0)
赞赏
感谢您的支持,我会继续努力哒!
版权属于:

运维茶馆

本文链接:

https://www.opstea.com/archives/typecho-blog.html(转载时请注明本文出处及文章链接)

评论 (0)
本篇文章评论功能已关闭