通过docker在云服务器运行Hentai@Home

发布于 2022-06-04  113 次阅读


来点色图。

Hentai@Home是什么?

Hentai@Home是e-hentai的P2P图床客户端,平时访问e-hentai时,图片就是从其他人的Hentai@Home节点加载的。自己运行Hentai@Home会有少量的GP和hath奖励,可以用来下载Archive等。

Hentai@Home wiki

服务器测速命令可以用:
wget -O "/root/speedtest" "https://raw.githubusercontent.com/BlueSkyXN/ChangeSource/master/speedtest" --no-check-certificate -T 30 -t 5 -d && chmod +x "/root/speedtest" && /root/speedtest

Dockerfile与docker-compose.yml

我的Dockerfile修改自这个repo,官方没有提供docker镜像和任何docker相关的文档,所以Dockerfile需要自己写了。

总的来讲就是从java8-11的jre或jdk开始,设好环境变量,下载客户端并解包,然后运行。变量按照 https://e-hentai.org/hentaiathome.php 当中的配置来设置。

Dockerfile:

FROM openjdk:8-jre-alpine

## Credentials
ENV HatH_ID xxxxx
ENV HatH_KEY xxxxxxxxxxxxxxxxxxxx

## Common settings
ENV HatH_PORT 3000

## Fetch binary
ENV HatH_VERSION 1.6.1
ENV HatH_DOWNLOAD_SHA256 b8889b2c35593004be061064fcb6d690ff8cbda9564d89f706f7e3ceaf828726
ENV HatH_DOWNLOAD_URL https://repo.e-hentai.org/hath/HentaiAtHome_$HatH_VERSION.zip

## Recommend default configuration
ENV HatH_USER hath
ENV HatH_USER_UID 1001
ENV HatH_PATH "/home/$HatH_USER/client"
ENV HatH_ARCHIVE hath.zip
ENV HatH_JAR HentaiAtHome.jar
# Hentai@Home parameters: https://ehwiki.org/wiki/Hentai@Home#Software
# --Xmx????m is arg for java, not jar
ENV HatH_ARGS --disable_logging

# Container Setup
RUN adduser -D "$HatH_USER" -u "$HatH_USER_UID"
USER "$HatH_USER"

RUN mkdir "$HatH_PATH" && \
    cd "$HatH_PATH" && \
    wget -q "$HatH_DOWNLOAD_URL" -O "$HatH_ARCHIVE" && \
# Two spaces between hash and filename is required to pass
# TODO: seperate TEST stage with sha256 checksum verification
    echo ""$HatH_DOWNLOAD_SHA256"  "$HatH_ARCHIVE"" | sha256sum -c && \
    unzip "$HatH_ARCHIVE" "$HatH_JAR" && \
    rm "$HatH_ARCHIVE" && \
    echo $(date +%s) > ${HatH_VERSION}_${HatH_DOWNLOAD_SHA256} && \
    mkdir -p "$HatH_PATH/data" && \
    chmod -R 775 "$HatH_PATH"

WORKDIR "$HatH_PATH"

# Expose the port
EXPOSE "$HatH_PORT"

#VOLUME ["$HatH_PATH/cache", "$HatH_PATH/data", "$HatH_PATH/download"]

# TODO: HEALTHCHECK

# CMD use with ENTRYPOINT
# write credential $HatH_ID-$HatH_KEY data/client_login
CMD echo -n $HatH_ID-${HatH_KEY} > $HatH_PATH/data/client_login && java -jar "$HatH_JAR" --port=$HatH_PORT $HatH_ARGS

设置UID是为了方便设置文件权限。

docker-compose.yml:

version: "3"

services:
  hath:
    build: .
    volumes:
      - ./cache:/home/hath/client/cache
      - ./data:/home/hath/client/data
      - ./download:/home/hath/client/download
    ports:
      - "3000:3000"
    container_name: hath
    restart: always
    networks:
      - default

修改文件权限

volumes中涉及的三个文件夹所有者都要改成Dockerfile中用户对应的UID1001,不然会提示权限有错。

运行后如果正常,ehentai的Hentai@Home管理页面中会显示客户端在线并Trust为正,Quality初始为1500,在达到2500前不会有访问,不必担心配置有误。


Sup