docker 部署 koodo-reader
简介
caddy 是一个使用 Go 构建的强大的企业级开源 web 服务器。
koodo-reader 是一个跨平台的现代电子书管理器和阅读器,其源码地址koodo-reader
安装
创建两个 volume 分别挂载到 /data和/config
构建koodo-reader静态资源
-
创建Dockerfile
FROM node:14-slim as builder RUN apt-get update && apt-get install -y jq curl wget python WORKDIR /app ### Get the latest release source code tarball RUN tarball_url=$(curl -s https://api.github.com/repos/troyeguo/koodo-reader/releases/latest | jq -r ".tarball_url") \ && wget -qO- $tarball_url \ | tar xvfz - --strip 1 ### --network-timeout 1000000 as a workaround for slow devices ### when the package being installed is too large, Yarn assumes it's a network problem and throws an error RUN yarn --network-timeout 1000000 ### Separate `yarn build` layer as a workaround for devices with low RAM. ### If build fails due to OOM, `yarn install` layer will be already cached. RUN yarn build ### Nginx or Apache can also be used, Caddy is just smaller in size FROM caddy:latest COPY ./config/Caddyfile /etc/caddy/Caddyfile COPY --from=builder /app/build /usr/share/caddy -
创建Caddyfile(其中端口号可以修改为你喜欢的)
# The Caddyfile is an easy way to configure your Caddy web server. # # Unless the file starts with a global options block, the first # uncommented line is always the address of your site. # # To use your own domain name (with automatic HTTPS), first make # sure your domain's A/AAAA DNS records are properly pointed to # this machine's public IP, then replace ":80" below with your # domain name. :1088 { # Set this path to your site's directory. root * /usr/share/caddy # Enable the static file server. file_server # Another common task is to set up a reverse proxy: # reverse_proxy localhost:8080 # Or serve a PHP site through php-fpm: # php_fastcgi localhost:9000 } # Refer to the Caddy docs for more information: # https://caddyserver.com/docs/caddyfile -
使用 docker-compose 构建和部署
version: '3' services: koodo: container_name: koodo-reader build: context: . dockerfile: Dockerfile ports: - "2080:1088/tcp" volumes: - "/Users/xxx/koodo-reader/config/data:/data" - "/Users/xxx/koodo-reader/config/config:/config" restart: unless-stopped -
构建和启动容器
docker-compose up --build --force-recreate --no-deps
如果镜像构建失败可以尝试本地构建,相关操作步骤如下:
-
项目目录下执行命令
yarn -
执行构建
yarn build -
修改Dockerfile为以下内容
相当于直接在本机构建静态资源
FROM caddy:latest COPY ./config/Caddyfile /etc/caddy/Caddyfile COPY ./build /usr/share/caddy -
构建
docker-compose up --build --force-recreate --no-deps -
推送到 docker hub
docker push
部署应用
这里我们使用 docker-compose 直接部署,配置文件如下:
version: "3"
networks:
traefik:
external: true
services:
server:
image: sakitamclone/koodo-reader:latest
container_name: koodo-reader
restart: always
volumes:
- "/containers/koodo-reader/data:/data"
- "/containers/koodo-reader/config:/config"
ports:
- "8123:1088"
networks:
- traefik
labels:
- "traefik.enable=true"
# 设置HTTP强制跳转HTTPS 中间件
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
# HTTP配置
- "traefik.http.routers.koodo-reader.rule=Host(`xx.xx.xx.com`)"
- "traefik.http.routers.koodo-reader.entrypoints=web"
# HTTPS配置
- "traefik.http.routers.koodo-reader-secure.rule=Host(`xx.xx.xxx.com`)"
- "traefik.http.routers.koodo-reader-secure.entrypoints=websecure"
- "traefik.http.routers.koodo-reader-secure.tls=true"
- "traefik.http.routers.koodo-reader-secure.tls.certresolver=le"
- "traefik.http.services.server-koodo-reader.loadbalancer.server.port=1088"