在数字时代,管理个人或家庭的图片和视频库是一项挑战。Immich服务提供了一个解决方案,它允许用户在本地网络存储设备上创建一个私人的、易于访问的媒体库。本文将指导您如何快速搭建Immich服务,让您能够体验和使用这一强大的图片管理工具。

准备工作

在开始之前,请确保您已经具备以下条件:

  • 一台Nas服务器,作为运行Immich服务的硬件基础。
  • Nas服务器上安装了Docker服务,这是运行Immich容器化应用的前提。
  • 确保Docker服务能够正常访问互联网,以便下载所需的镜像和文件。

创建Immich项目目录

首先,我们需要在Nas服务器上创建一个专门的目录来存放Immich服务的相关文件。打开终端或命令提示符,执行以下命令:

$ mkdir ./immich-app

这将创建一个名为immich-app的新目录。

下载必要的文件

接下来,进入新创建的目录,并下载Immich服务所需的docker-compose.ymlexample.env配置文件:

$ cd immich-app
$ 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

或者,您可以使用curl命令来下载这些文件:

$ curl -o docker-compose.yml https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
$ curl -o .env https://github.com/immich-app/immich/releases/latest/download/example.env

启动Immich服务

下载完所有文件后,使用Docker Compose启动Immich服务:

$ docker compose up -d

这条命令将后台运行Immich服务。如果这是您第一次运行Immich,它将启动初始化设置向导。

![[Pasted_image_20240719155945.png|350]]

服务启动后,打开浏览器并访问http://localhost:2283,您将看到Immich的初始配置界面。在这里,输入您的管理员账号和其他必要信息以完成设置。

疑难问题解决

如果在docker compose up运行服务不成功,系统会给你以下错误提示,以下是相关提示和解决办法。

情况1:

ERROR: The Compose file './docker-compose.yml' is invalid because:
'name' does not match any of the regexes: '^x-'

处理办法:

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

删除docker-compose.yml文档中,最前面包含name那一行内容。应该是docker-compose 以前的版本并不支持,删掉不影响使用。

情况2:

ERROR: The Compose file './docker-compose.yml' is invalid because:
You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1. For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/

处理办法:

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

version: 3.3 # 增加这行

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:

由于docker-compose旧版本需要声明格式版本,我们补上即可。

情况3:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.database.healthcheck value 'start_interval' does not match any of the regexes: '^x-'

处理办法:

...

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

...

docker-compose.yml文件中的尾部找到start_interval这行内容,删掉或者注释掉就可以了。这个旧版本的docker-compose不支持导致上面错误提示。

情况4:

$ sudo docker-compose --env-file .env up -d

Starting immich_postgres ...
immich_redis is up-to-date
Starting immich_postgres ... error

ERROR: for immich_postgres Cannot start service database: Bind mount failed: '/volume2/docker/immich-app/postgres' does not exists

ERROR: for database Cannot start service database: Bind mount failed: '/volume2/docker/immich-app/postgres' does not exists

旧版本docker-compose并不会自动生成目录,所以我们这里需要手动创建两个目录来让它能正常运行。

$ mkdir library postgres

结语

通过上述步骤,您应该能够快速搭建并运行Immich服务。Immich不仅提供了基本的图片和视频存储功能,还支持智能搜索、人脸识别等高级功能,帮助您更好地管理和访问您的媒体库。接下来的文章将深入探讨如何使用Immich的高级功能,敬请期待。