leanote的docker部署

2020-01-09  本文已影响0人  FoolishFlyFox

搭建leanote服务器环境的步骤:

FROM jim3ma/leanote
# foolishflyfox/leanote:1.1 修复wkhtmltox不能正常使用问题
RUN apt purge -y wkhtmltopdf
RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.jessie_amd64.deb
RUN apt update
RUN apt install xfonts-75dpi
RUN dpkg -i wkhtmltox_0.12.5-1.jessie_amd64.deb
RUN rm wkhtmltox_0.12.5-1.jessie_amd64.deb

# foolishflyfox/leanote:1.2 dockerfile 改变文件映射
RUN rm -rf /leanote/public
RUN rm -rf /leanote/mongodb_backup
RUN ln -s /leanote/data/public /leanote/public
RUN ln -s /leanote/data/mongodb_backup /leanote/mongodb_backup

3、从 github 上下载 源码,解压后执行(pwd为~/leanote):

mongodb用到的命令:

4、编写docker-compose.yml

version: '2' 
services:
  leanote:
    image: foolishflyfox/leanote:latest
    network_mode: "host"
    volumes:
      - ./leanote-data:/leanote/data
      - ./app.conf:/leanote/conf/app.conf
    restart: always

现在文件的映射关系为:
a. docker:/leanote/public -> host:leanote/leanote-data/public
b. docker:/leanote/mongodb_backup -> host:leanote/leanote-data/mongodb_backup
c. docker:/leanote/files -> host:leanote/leanote-data/files

5、启动docker-compose up -d,之后就可以访问了,默认的端口号为9000,默认有两个账号:

user1 username: admin, password: abc123 (administrator who can manage Leanote)
user2 username: demo@leanote.com, password: demo@leanote.com (just for demonstration)

如果用上面的docker-compose.yml创建的容器已经存在,直接启动该容器;如果不存在,创建后再启动。另外还有3个命令:

6、博客迁移:

7、博客备份

可以写个脚本按日期进行备份,同一天中的每一次备份都在同一个文件夹中,并只保存最后一次备份:

#!/bin/bash
leanote_backup_dir=~/leanote-backup
TIMESTAMP=$(date +"%Y%m%d")
echo $TIMESTAMP
mkdir $leanote_backup_dir/$TIMESTAMP
rm -rf $leanote_backup_dir/$TIMESTAMP/*
tar -cjvf $leanote_backup_dir/$TIMESTAMP/leanote.tar.bz2 ~/leanote
mongodump -d leanote -o $leanote_backup_dir/$TIMESTAMP/leanote-db

也可以用git进行备份,shell脚本为

#!/bin/bash

leanote_dir=$HOME/leanote
leanote_backup_dir=$HOME/GitRep/leanotebackup

if [ $# -lt 1 ] 
then
    message=$(date +"%Y/%m/%d %H:%M:%S")
    message="$message update the date"
else
    message="$1"
fi

echo $message
cd $leanote_backup_dir

rsync --delete -rv $leanote_dir .
mongodump -d leanote -o $leanote_backup_dir/leanote-db
git add .
git commit -m "$message"
git push

cd -

注意:需要通过git config --global credential.helper store设置免密push。

附:

Q:如何修改图标?
A:将 leanote-data/public/images/favicon.ico 替换成想要的图标;

Q: 如何解决创建博客的时间和真实事件相差8小时的问题?
A:这是因为docker容器中的时间没有和主机时间同步造成的,在docker-compose.yml中添加主机/etc/localtime到容器/etc/localtime的映射即可:

version: '2' 
services:
  leanote:
    image: foolishflyfox/leanote:latest
    network_mode: "host"
    volumes:
      - ./leanote-data:/leanote/data
      - ./app.conf:/leanote/conf/app.conf
      - /etc/localtime:/etc/localtime:ro
    restart: always

上一篇下一篇

猜你喜欢

热点阅读