Docker: quick setup of semi portable Immich installation

Introduction

The default docker-compose.yml and .env from (Immich)[https://github.com/immich-app/immich] uses docker volumes. I don’t like docker volumes, as they are harder to transport. So I usually just change the location of services to be in one directory, together with the docker-compose.yml file and the .env file.

Here I will show my config, and a quick and dirty way to move the Immich application from one Linux server to another.

TL/DR:

#--- just anywhere where you want your immich installation
cd /var/lib/ops
mkdir immich
cd immich
mkdir -p ./data/{library,model-cache,postgres}

#--- on linux, change the ownership of this directory, on Mac with Docker desktop don't
sudo chown 999 data/postgres
  • Create a .env file
UPLOAD_LOCATION=./data/library
IMMICH_VERSION=release
DB_PASSWORD=postgres
DB_HOSTNAME=immich_postgres
DB_USERNAME=postgres
DB_DATABASE_NAME=immich
REDIS_HOSTNAME=immich_redis
  • Create the docker-compose.yml file:
version: "3.8"

#
# 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}
    command: [ "start.sh", "immich" ]
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    ports:
      - 2283:3001
    depends_on:
      - redis
      - database
    restart: always

  immich-microservices:
    container_name: immich_microservices
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    # extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/hardware-transcoding
    #   file: hwaccel.transcoding.yml
    #   service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
    command: [ "start.sh", "microservices" ]
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    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:
      - ./data/model-cache:/cache
    env_file:
      - .env
    restart: always

  redis:
    container_name: immich_redis
    image: registry.hub.docker.com/library/redis:6.2-alpine@sha256:51d6c56749a4243096327e3fb964a48ed92254357108449cb6e23999c37773c5
    restart: always

  database:
    container_name: immich_postgres
    image: registry.hub.docker.com/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:90724186f0a3517cf6914295b5ab410db9ce23190a2d9d0b9dd6463e3fa298f0
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
    restart: always

#volumes:
#  pgdata:
#  model-cache:

Now you start the application and visit Immich at https://localhost:2283

Move Immich

To move Immich from one server to antoher:

  • On the source system:
#--- test that you have both ssh and sudo access on "the other side"
$ ssh ops@wue-docker-l02 sudo ls -la /etc/hosts
-rw-r--r-- 1 root root 558 Mar  1 13:38 /etc/hosts


#--- shut down the containers, then copy the files over. I like "pv" to show progress
sudo apt install pv

cd /var/lib/ops/immich
docker compose down
cd ..
#--- get the size of immich
sudo du -hs immich
137G	immich

#--- with pv
tar cpf - immich | pv -r -a -p -s 137G  --timer --eta | ssh ops@wue-docker-l02 "cd /home/ops/docker/ ; sudo tar xpf -"

#--- without pv
tar cpf - immich | ssh ops@wue-docker-l02 "cd /home/ops/docker/ ; sudo tar xpf -"
  • On the destination system:
cd /home/ops/docker/immich
docker compose up -d

References