Docker Compose [推荐]
Docker Compose 是用于生产环境中运行 Immich 的推荐方法。以下是使用 Docker Compose 部署 Immich 的步骤。
Step 1 - Download the required files
Create a directory of your choice (e.g. ./immich-app
) to hold the docker-compose.yml
and .env
files.
mkdir ./immich-app
cd ./immich-app
Download docker-compose.yml
and example.env
by running the following commands:
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
You can alternatively download these two files from your browser and move them to the directory that you created, in which case ensure that you rename example.env
to .env
.
Step 2 - Populate the .env file with custom values
# You can find documentation for all the supported env variables at https://immich.app/docs/install/environment-variables
# The location where your uploaded files are stored
UPLOAD_LOCATION=./library
# The location where your database files are stored. Network shares are not supported for the database
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=Etc/UTC
# 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
# Please use only the characters `A-Za-z0-9`, without special characters or spaces
DB_PASSWORD=postgres
# The values below this line do not need to be changed
###################################################################################
DB_USERNAME=postgres
DB_DATABASE_NAME=immich
- Populate
UPLOAD_LOCATION
with your preferred location for storing backup assets. It should be a new directory on the server with enough free space. - Consider changing
DB_PASSWORD
to a custom value. Postgres is not publicly exposed, so this password is only used for local authentication. To avoid issues with Docker parsing this value, it is best to use only the charactersA-Za-z0-9
.pwgen
is a handy utility for this. - Set your timezone by uncommenting the
TZ=
line. - Populate custom database information if necessary.
Step 3 - Start the containers
From the directory you created in Step 1 (which should now contain your customized docker-compose.yml
and .env
files), run the following command to start Immich as a background service:
docker compose up -d
如果您遇到错误,例如 unknown shorthand flag: 'd' in -d
或 open <location of your .env file>: permission denied
,可能是您使用了错误的 Docker 版本。(例如,在 Ubuntu 22.04.3 LTS 中使用 docker.io 软件包时会发生这种情况。)您可以通过按照针对您发行版的Docker Engine 安装完整流程(尤其是“卸载旧版本”和“使用 apt/rpm 仓库安装”部分)来解决问题。这些步骤将替换发行版自带的 Docker 软件包为官方版本。
请注意,正确的命令是 docker compose
,而不是 docker-compose
。如果您在原生 Ubuntu 22.04 上尝试后者, 将以不同的方式失败:
Compose 文件 './docker-compose.yml' 无效,因为:
'name' 与以下正则表达式不匹配:'^x-'
请参阅前段关于从官方 Docker 仓库安装的内容。
如果您遇到错误 can't set healthcheck.start_interval as feature require Docker Engine v25 or later
,建议注释 docker-compose.yml
文件中 database
部分的 start_interval
行。