mirror of https://github.com/mindoc-org/mindoc.git
sync files from docker to host
parent
2dcffaf1fe
commit
ac772930b2
10
Dockerfile
10
Dockerfile
|
@ -113,11 +113,15 @@ RUN ebook-convert --version
|
|||
RUN rm -rf /tmp/calibre-cache
|
||||
|
||||
# refer: https://docs.docker.com/engine/reference/builder/#volume
|
||||
VOLUME /mindoc
|
||||
# 数据同步目录
|
||||
VOLUME /mindoc-sync-host
|
||||
|
||||
# refer: https://docs.docker.com/engine/reference/builder/#expose
|
||||
EXPOSE 8181/tcp
|
||||
|
||||
# 如果配置文件不存在就复制
|
||||
RUN cp --no-clobber /mindoc/conf/app.conf.example /mindoc/conf/app.conf
|
||||
|
||||
ENV ZONEINFO=/mindoc/lib/time/zoneinfo.zip
|
||||
RUN chmod +x /mindoc/start.sh
|
||||
|
||||
|
@ -126,4 +130,6 @@ ENTRYPOINT ["/bin/bash", "/mindoc/start.sh"]
|
|||
# https://docs.docker.com/engine/reference/commandline/build/#options
|
||||
# docker build --progress plain --rm --build-arg TAG=2.0.1 --tag gsw945/mindoc:2.0.1 .
|
||||
# https://docs.docker.com/engine/reference/commandline/run/#options
|
||||
# docker run --rm -it -p 8181:8181 -v "mindoc-docker":"/mindoc" --name mindoc -e MINDOC_ENABLE_EXPORT=true -d gsw945/mindoc:2.0.1
|
||||
# set MINDOC=//d/mindoc # windows
|
||||
# export MINDOC=/home/ubuntu/mindoc-docker # linux
|
||||
# docker run --rm -it -p 8181:8181 -v "%MINDOC%":"/mindoc-sync-host" --name mindoc -e MINDOC_ENABLE_EXPORT=true -d gsw945/mindoc:2.0.1
|
||||
|
|
15
README.md
15
README.md
|
@ -100,11 +100,20 @@ HTTP_PORT 程序监听的端口号
|
|||
MINDOC_ENABLE_EXPORT 开启导出(默认为false)
|
||||
```
|
||||
|
||||
举个栗子-当前(公开)镜像(信息页面: https://cr.console.aliyun.com/images/cn-hangzhou/mindoc-org/mindoc/detail)
|
||||
### 举个栗子-当前(公开)镜像(信息页面: https://cr.console.aliyun.com/images/cn-hangzhou/mindoc-org/mindoc/detail)
|
||||
##### Windows
|
||||
```bash
|
||||
docker run -it --name=mindoc --restart=always -v /mindoc:/mindoc -p 8181:8181 -e MINDOC_ENABLE_EXPORT=true -d registry.cn-hangzhou.aliyuncs.com/mindoc-org/mindoc:v2.1-beta.1
|
||||
set MINDOC=//d/mindoc
|
||||
docker run -it --name=mindoc --restart=always -v "${MINDOC}":"/mindoc-sync-host" -p 8181:8181 -e MINDOC_ENABLE_EXPORT=true -d registry.cn-hangzhou.aliyuncs.com/mindoc-org/mindoc:v2.1-beta.4
|
||||
```
|
||||
举个栗子-更多环境变量示例(镜像已过期,仅供参考,请以当前镜像为准)
|
||||
|
||||
##### Linux、Mac
|
||||
```bash
|
||||
export MINDOC=/home/ubuntu/mindoc-docker
|
||||
docker run -it --name=mindoc --restart=always -v "%MINDOC%":"/mindoc-sync-host" -p 8181:8181 -e MINDOC_ENABLE_EXPORT=true -d registry.cn-hangzhou.aliyuncs.com/mindoc-org/mindoc:v2.1-beta.4
|
||||
```
|
||||
|
||||
##### 举个栗子-更多环境变量示例(镜像已过期,仅供参考,请以当前镜像为准)
|
||||
```bash
|
||||
docker run -p 8181:8181 --name mindoc -e DB_ADAPTER=mysql -e MYSQL_PORT_3306_TCP_ADDR=10.xxx.xxx.xxx -e MYSQL_PORT_3306_TCP_PORT=3306 -e MYSQL_INSTANCE_NAME=mindoc -e MYSQL_USERNAME=root -e MYSQL_PASSWORD=123456 -e httpport=8181 -d daocloud.io/lifei6671/mindoc:latest
|
||||
```
|
||||
|
|
34
start.sh
34
start.sh
|
@ -1,10 +1,36 @@
|
|||
#!/bin/bash
|
||||
set -eux
|
||||
|
||||
if [ ! -f "/mindoc/conf/app.conf" ] ; then
|
||||
cp /mindoc/conf/app.conf.example /mindoc/conf/app.conf
|
||||
fi
|
||||
|
||||
# 数据库等初始化
|
||||
/mindoc/mindoc_linux_amd64 install
|
||||
|
||||
# 导出同步检查
|
||||
mkdir -p /mindoc-sync-host
|
||||
if ! [ -f "/mindoc-sync-host/sync.sh" ]; then
|
||||
# 同步方向: docker->HOST 或 HOST -> docker
|
||||
# echo "export MINDOC_SYNC=" >> /mindoc-sync-host/sync.sh # 不同步
|
||||
echo "export MINDOC_SYNC=docker2host" >> /mindoc-sync-host/sync.sh # 默认 docker->HOST
|
||||
|
||||
# 同步内容
|
||||
# conf: 配置
|
||||
# database: sqlite方式数据库
|
||||
# runtime: 运行时数据(日志等)
|
||||
# static: 静态文件
|
||||
# uploads: 上传文件
|
||||
# views: 页面视图
|
||||
# echo "export SYNC_LIST='conf;database;runtime;static;uploads;views'" >> /mindoc-sync-host/sync.sh # 同步所有内容
|
||||
# echo "export SYNC_LIST=" >> /mindoc-sync-host/sync.sh # 不同步任何内容
|
||||
echo "export SYNC_LIST='conf;database;uploads'" >> /mindoc-sync-host/sync.sh # 同步conf、database、uploads
|
||||
|
||||
# 同步操作(sync/copy/sync --dry-run 等,具体参考rclone文档,host2docker务必谨慎操作)
|
||||
# echo "export SYNC_ACTION=sync --dry-run" >> /mindoc-sync-host/sync.sh # 无操作且仅显示同步文件信息(--dry-run)
|
||||
echo "export SYNC_ACTION=sync" >> /mindoc-sync-host/sync.sh # 默认同步
|
||||
|
||||
# 同步脚本
|
||||
echo "source /mindoc/sync_host.sh" >> /mindoc-sync-host/sync.sh
|
||||
fi
|
||||
# 同步操作
|
||||
source /mindoc-sync-host/sync.sh
|
||||
|
||||
# 运行
|
||||
/mindoc/mindoc_linux_amd64
|
|
@ -0,0 +1,40 @@
|
|||
#!/bin/bash
|
||||
set -eux
|
||||
|
||||
if ! [ -x "$(command -v rclone)" ]; then
|
||||
apt install rclone -y
|
||||
else
|
||||
whereis rclone
|
||||
fi
|
||||
|
||||
|
||||
export MINDOC_SYNC="${MINDOC_SYNC:=}"
|
||||
export SYNC_LIST="${SYNC_LIST:=}"
|
||||
export SYNC_ACTION="${SYNC_ACTION:=sync --dry-run}"
|
||||
export HOST_DIR=/mindoc-sync-host
|
||||
export DOCKER_DIR=/mindoc
|
||||
|
||||
function doSyncCopy() {
|
||||
rclone $SYNC_ACTION --progress --exclude .git* --exclude .git/** "${1}" "${2}"
|
||||
}
|
||||
|
||||
function doSync() {
|
||||
case $MINDOC_SYNC in
|
||||
"docker2host")
|
||||
doSyncCopy "${DOCKER_DIR}/${1}" "${HOST_DIR}/${1}"
|
||||
;;
|
||||
"host2docker")
|
||||
doSyncCopy "${HOST_DIR}/${1}" "${DOCKER_DIR}/${1}"
|
||||
;;
|
||||
*)
|
||||
printenv | grep MINDOC_SYNC
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
export IFS=";"
|
||||
if ! [ -z "${SYNC_LIST}" ]; then
|
||||
for item in $SYNC_LIST; do
|
||||
doSync "${item}"
|
||||
done
|
||||
fi
|
Loading…
Reference in New Issue