本人用的黑群晖,升级dsm版本比较麻烦并且用着也没什么问题,就没有动力升级到dsm7,结果突然发现安卓版本的moments在手机上闪退了,应该是安卓大版本更新的原因,无奈找到了immich作为群晖moments套件的替代品,目前网页版原生已支持中文,可放心使用。本文记录下使用docker-compose在群晖dsm6安装immich过程。

准备

docker-compose

官方要求使用docker compose version 2.x,我目前的docker版本为20.10.3,跑的容器比较多,也不想重启了,就打算只升级docker-compose试试,不过后来发现只升级docker-compose应该不行,还得修改docker-compose文件,不过也不确定不升级是不是还有别的问题,就先记录下这个步骤了。正常升级docker 版本后,应该会自带docker compose命令,注意中间没有-。

下载docker-compose文件 https://github.com/docker/compose/releases#:~:text=2%20weeks%20ago-,docker%2Dcompose%2Dlinux%2Dx86_64,-60.2%20MB

上传文件到群晖/usr/local/bin 目录,并修改文件名为docker-compose
授权

1
chmod +x /usr/local/bin/docker-compose

测试一下,完美

1
2
root@DS918Plus:~# docker-compose --version
Docker Compose version v2.28.1

创建目录

创建immich的主目录,在该目录中再创建machinecache和postgres目录,目录结构如下,待会会说明docker-compose.yml和.env文件怎么来

1
2
3
4
5
6
7
8
9
10
root@DS918Plus:/volume2/docker/immich# ls -la
total 20
drwxrwxrwx+ 1 hy users 114 Jul 5 09:20 .
drwxrwxrwx+ 1 root root 336 Jul 4 17:19 ..
-rwxrwxrwx 1 hy users 2530 Jul 4 17:39 docker-compose.yml
-rwxrwxrwx+ 1 hy users 8196 Jul 4 17:19 .DS_Store
drwxrwxrwx+ 1 root users 168 Jul 4 17:19 @eaDir
-rwxrwxrwx 1 root root 895 Jul 5 09:20 .env
drwxrwxrwx+ 1 root root 8 Jul 5 09:37 machinecache
drwx------ 1 999 users 570 Jul 5 08:00 postgres

准备运行和配置文件

进入immich目录,运行下面两个命令就可以下载官方的模板,当然还需要修改

1
2
3
wget -O docker-compose.yml https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml

wget -O .env https://github.com/immich-app/immich/releases/latest/download/example.env

如下为.env文件,我修改了tz为中国时区,这没啥好说,增加了HF_ENDPOINT=”https://hf-mirror.com“ 这个变量,目的是为了机器学习下载模型能够使用这个镜像站,不然默认的下载地址大概率是下不到的。UPLOAD_LOCATION修改为你想存储照片的目录。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# You can find documentation for all the supported env variables at https://immich.app/docs/install/environment-variables
HF_ENDPOINT="https://hf-mirror.com"
# The location where your uploaded files are stored
UPLOAD_LOCATION=/volume2/photo
# The location where your database files are stored
DB_DATA_LOCATION=./postgres

# To set a timezone, uncomment the next line and change Etc/UTC to a TZ identifier from this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
TZ=Asia/Shanghai

# The Immich version to use. You can pin this to a specific version like "v1.71.0"
IMMICH_VERSION=release

# Connection secret for postgres. You should change it to a random password
DB_PASSWORD=postgres

# The values below this line do not need to be changed
###################################################################################
DB_USERNAME=postgres
DB_DATABASE_NAME=immich

如下为docker-compose.yml文件,几个修改点通过注释说明

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#

# WARNING: Make sure to use the docker-compose.yml of the current release:

#

# https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml

#

# The compose file on main may not be compatible with the latest release.

#



name: immich



services:

immich-server:

container_name: immich_server

image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}

# extends:

# file: hwaccel.transcoding.yml

# service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding

volumes:

- ${UPLOAD_LOCATION}:/usr/src/app/upload

# 这里存了原来moments里的照片 不挂载也没关系

- /volume2/homes/hy/Drive/Moments:/mnt/media/Photos

- /etc/localtime:/etc/localtime:ro

env_file:

- .env

ports:

- 2283:3001

depends_on:

- redis

- database

restart: always



immich-machine-learning:

container_name: immich_machine_learning

# For hardware acceleration, add one of -[armnn, cuda, openvino] to the image tag.

# Example tag: ${IMMICH_VERSION:-release}-cuda

image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}

# extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/ml-hardware-acceleration

# file: hwaccel.ml.yml

# service: cpu # set to one of [armnn, cuda, openvino, openvino-wsl] for accelerated inference - use the `-wsl` version for WSL2 where applicable

volumes:

#保存模型文件,还挺大的,不然后面容器重启会重新下载

- /volume2/docker/immich/machinecache:/cache

env_file:

- .env

restart: always



redis:

container_name: immich_redis

image: docker.io/redis:6.2-alpine@sha256:328fe6a5822256d065debb36617a8169dbfbd77b797c525288e465f56c1d392b

healthcheck:

test: redis-cli ping || exit 1

restart: always



database:

container_name: immich_postgres

image: docker.io/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:90724186f0a3517cf6914295b5ab410db9ce23190a2d9d0b9dd6463e3fa298f0

environment:

POSTGRES_PASSWORD: ${DB_PASSWORD}

POSTGRES_USER: ${DB_USERNAME}

POSTGRES_DB: ${DB_DATABASE_NAME}

POSTGRES_INITDB_ARGS: '--data-checksums'

volumes:

- ${DB_DATA_LOCATION}:/var/lib/postgresql/data

# docker-compose或者docker版本的问题就在这里了,干脆直接注释掉,关系不大

# healthcheck:

# test: pg_isready --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' || exit 1; Chksum="$$(psql --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' --tuples-only --no-align --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')"; echo "checksum failure count is $$Chksum"; [ "$$Chksum" = '0' ] || exit 1

# interval: 5m

# start_interval: 30s

# start_period: 5m

command: ["postgres", "-c" ,"shared_preload_libraries=vectors.so", "-c", 'search_path="$$user", public, vectors', "-c", "logging_collector=on", "-c", "max_wal_size=2GB", "-c", "shared_buffers=512MB", "-c", "wal_compression=on"]

restart: always



volumes:

model-cache:

预拉取镜像

docker-compose.yml文件中的镜像建议提前拉取,可能需要配置代理或者其他镜像加速办法,有点蛋疼。

启动

这就很简单了,在docker-compose.yml所在的目录中执行如下命令,注意和官方文档中的进行区分下,中间有个-

1
docker-compose up -d 

升级

其实就是镜像重新拉,然后重启

1
docker-compose pull && docker-compose up -d

更换模型

官方默认的机器学习模型用的ViT-B-32__openai,很可惜不支持中文,换掉!!换成XLM-Roberta-Large-Vit-B-16Plus,登录管理页面直接修改保存即可,然后重新运行智能搜索任务
image.png
image.png

由于我渣渣的蜗牛星际cpu性能,跑完任务估计得好几天。。。就不给大家看智能搜索结果了,目测大概5s能完成一张图片处理,我觉得也还行啊。

参考

Docker Compose [Recommended] | Immich
HF-Mirror