mindoc-org / mindoc

Golang实现的基于beego框架的接口在线文档管理系统
https://mindoc.com.cn/docs/mindochelp
Apache License 2.0
7.34k stars 1.91k forks source link

> > > 目前利用rclone进行数据导出,后续计划将可备份的文件`conf`、`views`、`uploads`、`database`拆离,就不需要rclone了 #738

Open keith-ch opened 3 years ago

keith-ch commented 3 years ago

目前利用rclone进行数据导出,后续计划将可备份的文件confviewsuploadsdatabase拆离,就不需要rclone了

为什么没有在dockerfile中安装rclone呢? 应用部署在内网的情况,考虑了吗?

这是个问题,我尽快解决掉 我按照新的docker-compose部署,还是无法访问。 那目前内网部署,还不支持,可以这么理解吗?

Originally posted by @keith-ch in https://github.com/mindoc-org/mindoc/issues/737#issuecomment-944054011

keith-ch commented 3 years ago

我用Dockfile方式制作了新镜像,加入了rclone。 容器启动后,浏览器还是无法访问 http://172.18.3.139:8181/ dockerfile新增: …… RUN apt install -y --no-install-recommends rclone ……

build命令: sudo docker build --progress plain --rm --build-arg TAG=0.0.2 --tag mindoc:0.0.2 .

docker-compose: services: mindoc: image: mindoc:0.0.2 privileged: false container_name: mindoc restart: always ports:

日志: `+++ rclone sync --progress --exclude '.git*' --exclude '.git/**' /mindoc/uploads /mindoc-sync-host/uploads 2021/10/21 17:28:26 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults Transferred: 1.924M / 1.924 MBytes, 100%, 397.130 MBytes/s, ETA 0s Errors: 0 Checks: 0 / 0, - Transferred: 9 / 9, 100% Elapsed time: 0s

2021/10/21 17:28:26.692 [I] [command.go:90] 数据库初始化完成.

2021/10/21 17:28:26.692 [I] [command.go:369] 正常初始化缓存配置.

2021/10/21 17:28:26.693 [I] [command.go:458] 缓存初始化完成.

MinDoc version => build time => start directory => /mindoc/mindoc_linux_amd64

2021/10/21 17:28:27.021 [I] [server.go:243] http server Running on http://:8181`

浏览器访问:

无法访问此网站172.18.3.139 拒绝了我们的连接请求。 请试试以下办法:

gsw945 commented 3 years ago

这个需要调试下,不确定问题。 调试方法: docker 连接到容器内,安装w3m(apt install w3m -y),然后w3m http://127.0.0.1:8181/ 看看能否访问,如果ok,在查看端口映射等问题。 docker-compose并没有严格测试。

keith-ch commented 3 years ago

可以访问了,谢谢!

InGramViking commented 3 years ago

image

如上图,a66754bfe453 是默认的Dockerfile构建出的镜像,a5e7872b8fb5是经过将默认Dockerfile修改后的大小,276ad4d1b073是添加了rclone后的大小,可以参考一下

FROM amd64/golang:1.13 AS build

ARG TAG=0.0.1

# 编译-环境变量
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn,direct
ENV CGO_ENABLED=1
ENV GOARCH=amd64
ENV GOOS=linux

# 工作目录
ADD . /go/src/github.com/mindoc-org/mindoc
WORKDIR /go/src/github.com/mindoc-org/mindoc

# 编译
RUN go env && go mod tidy -v && go build -o mindoc_linux_amd64 -ldflags "-w -s -X 'main.VERSION=$TAG' -X 'main.BUILD_TIME=`date`' -X 'main.GO_VERSION=`go version`'" && rm -rvf appveyor.yml docker-compose.yml Dockerfile .travis.yml .gitattributes .gitignore go.mod go.sum main.go README.md conf/*.go cache commands controllers converter .git .github graphics mail models routers utils && cp conf/app.conf.example conf/app.conf && ./mindoc_linux_amd64 version

# Ubuntu 20.04
FROM ubuntu:focal

# 切换默认shell为bash
SHELL ["/bin/bash", "-c"]

COPY --from=build /go/src/github.com/mindoc-org/mindoc /mindoc
WORKDIR /mindoc
# 时区设置(如果不设置, calibre依赖的tzdata在安装过程中会要求选择时区)
ENV TZ=Asia/Shanghai
ENV PATH=$PATH:/opt/calibre
# 设置calibre相关环境变量
ENV QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox"
ENV QT_QPA_PLATFORM='offscreen'
ENV ZONEINFO=/mindoc/lib/time/zoneinfo.zip
# tzdata的前端类型默认为readline(Shell情况下)或dialog(支持GUI的情况下)
ARG DEBIAN_FRONTEND=noninteractive

RUN mkdir -p /usr/share/fonts/win/ /tmp/calibre-cache /opt/calibre  && mv simsun.ttc /usr/share/fonts/win/ && chmod a+r /usr/share/fonts/win/simsun.ttc && mv /etc/apt/sources.list /etc/apt/sources.list-backup && echo 'deb http://archive.ubuntu.com/ubuntu/ focal main restricted' > /etc/apt/sources.list && apt-get update && apt install -y ca-certificates && echo $'\
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse'\
> /etc/apt/sources.list && apt-get update && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && apt install -y apt-transport-https ca-certificates curl wget xz-utils && apt install -y --no-install-recommends tzdata && dpkg-reconfigure --frontend noninteractive tzdata && apt install -y rclone libgl-dev libnss3-dev libxcomposite-dev libxrandr-dev libxi-dev fonts-wqy-microhei fonts-wqy-zenhei locales language-pack-zh-hans language-pack-zh-hans-base && locale-gen "zh_CN.UTF-8" && update-locale LANG=zh_CN.UTF-8 && curl -s http://code.calibre-ebook.com/latest>/tmp/calibre-cache/version && wget -O /tmp/calibre-cache/calibre-x86_64.txz -c https://download.fastgit.org/kovidgoyal/calibre/releases/download/v`cat /tmp/calibre-cache/version`/calibre-`cat /tmp/calibre-cache/version`-x86_64.txz && tar xJof /tmp/calibre-cache/calibre-x86_64.txz -C /opt/calibre && ebook-convert --version && rm -rf /tmp/calibre-cache && cp --no-clobber /mindoc/conf/app.conf.example /mindoc/conf/app.conf && chmod +x /mindoc/start.sh && apt clean

ENV LANG="zh_CN.UTF-8"
ENV LANGUAGE="zh_CN:en"
ENV LC_ALL="zh_CN.UTF-8"
# refer: https://docs.docker.com/engine/reference/builder/#volume
# 数据同步目录
VOLUME /mindoc-sync-host

# refer: https://docs.docker.com/engine/reference/builder/#expose
EXPOSE 8181/tcp

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
# 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
keith-ch commented 2 years ago

image

如上图,a66754bfe453 是默认的Dockerfile构建出的镜像,a5e7872b8fb5是经过将默认Dockerfile修改后的大小,276ad4d1b073是添加了rclone后的大小,可以参考一下

FROM amd64/golang:1.13 AS build

ARG TAG=0.0.1

# 编译-环境变量
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn,direct
ENV CGO_ENABLED=1
ENV GOARCH=amd64
ENV GOOS=linux

# 工作目录
ADD . /go/src/github.com/mindoc-org/mindoc
WORKDIR /go/src/github.com/mindoc-org/mindoc

# 编译
RUN go env && go mod tidy -v && go build -o mindoc_linux_amd64 -ldflags "-w -s -X 'main.VERSION=$TAG' -X 'main.BUILD_TIME=`date`' -X 'main.GO_VERSION=`go version`'" && rm -rvf appveyor.yml docker-compose.yml Dockerfile .travis.yml .gitattributes .gitignore go.mod go.sum main.go README.md conf/*.go cache commands controllers converter .git .github graphics mail models routers utils && cp conf/app.conf.example conf/app.conf && ./mindoc_linux_amd64 version

# Ubuntu 20.04
FROM ubuntu:focal

# 切换默认shell为bash
SHELL ["/bin/bash", "-c"]

COPY --from=build /go/src/github.com/mindoc-org/mindoc /mindoc
WORKDIR /mindoc
# 时区设置(如果不设置, calibre依赖的tzdata在安装过程中会要求选择时区)
ENV TZ=Asia/Shanghai
ENV PATH=$PATH:/opt/calibre
# 设置calibre相关环境变量
ENV QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox"
ENV QT_QPA_PLATFORM='offscreen'
ENV ZONEINFO=/mindoc/lib/time/zoneinfo.zip
# tzdata的前端类型默认为readline(Shell情况下)或dialog(支持GUI的情况下)
ARG DEBIAN_FRONTEND=noninteractive

RUN mkdir -p /usr/share/fonts/win/ /tmp/calibre-cache /opt/calibre  && mv simsun.ttc /usr/share/fonts/win/ && chmod a+r /usr/share/fonts/win/simsun.ttc && mv /etc/apt/sources.list /etc/apt/sources.list-backup && echo 'deb http://archive.ubuntu.com/ubuntu/ focal main restricted' > /etc/apt/sources.list && apt-get update && apt install -y ca-certificates && echo $'\
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse\n\
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse\
\n# deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse'\
> /etc/apt/sources.list && apt-get update && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && apt install -y apt-transport-https ca-certificates curl wget xz-utils && apt install -y --no-install-recommends tzdata && dpkg-reconfigure --frontend noninteractive tzdata && apt install -y rclone libgl-dev libnss3-dev libxcomposite-dev libxrandr-dev libxi-dev fonts-wqy-microhei fonts-wqy-zenhei locales language-pack-zh-hans language-pack-zh-hans-base && locale-gen "zh_CN.UTF-8" && update-locale LANG=zh_CN.UTF-8 && curl -s http://code.calibre-ebook.com/latest>/tmp/calibre-cache/version && wget -O /tmp/calibre-cache/calibre-x86_64.txz -c https://download.fastgit.org/kovidgoyal/calibre/releases/download/v`cat /tmp/calibre-cache/version`/calibre-`cat /tmp/calibre-cache/version`-x86_64.txz && tar xJof /tmp/calibre-cache/calibre-x86_64.txz -C /opt/calibre && ebook-convert --version && rm -rf /tmp/calibre-cache && cp --no-clobber /mindoc/conf/app.conf.example /mindoc/conf/app.conf && chmod +x /mindoc/start.sh && apt clean

ENV LANG="zh_CN.UTF-8"
ENV LANGUAGE="zh_CN:en"
ENV LC_ALL="zh_CN.UTF-8"
# refer: https://docs.docker.com/engine/reference/builder/#volume
# 数据同步目录
VOLUME /mindoc-sync-host

# refer: https://docs.docker.com/engine/reference/builder/#expose
EXPOSE 8181/tcp

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
# 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

兄弟厉害,镜像size优化确实有门道。 a5e7872b8fb5你这个修改的内容主要是哪些,修改后的镜像能否正常跑起来吗?