Immich and Synology Photos -Immich – Part 3/4

Cathing Up

So in this third post we are finally going to set up Immich. If you thought this was supposed to be click and run you will be disappointed. Many times you read how easy it is to set up various programs but I think that people either lie, do it wrong or maybe some actually are super smart. Either way you will need some configuration. Also note that Immich in under heavy development so you might want to wait until you go all in until the stable release is here witch is suppose to be in end of 2024.

Expectations

Your expectations. Browsing your photos.

Reality… Terminal. Containers do not start as there is a yaml indention error on line 546.

Install

There are some steps to get it up and running. I also noticed when reading the Immich docs that they only support Docker compose v2. I have been running v1. The difference is if you use “docker-compose or “docker compose” Anyway i did an upgrade here. Also I had to re add the repository shown here. After this I was able to run the command below and after start my containers via “sudo docker compose up -d”. It looks a little bit different when you start the containers. Verify via “docker compose version”.

Make sure to read the Immich docs before continuing.

sudo apt-get install docker-compose-plugin

I think it could be a good idea to make sure Docker is up to date as well. You can run:

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Docker Compose files

Ok, Now we can start to set up the files. I did some modifications to my compose files. It might have been the fact that Docker compose was not up to date or not. Top in the container it clearly reads that you must check this. And I ignored it at first. Here is my file. I guess you should grab the latest from Immich and just use mine as a reference. I have put my files in a separate folder.

networks:
  default:
    external: true
    name: planet4_shared
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:
# Do not edit the next line. If you want to change the media storage location on your system, edit the value of UPLOAD_LOCATION in the .env file
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    ports:
      - 2283:3001
    depends_on:
      - redis
      - database
    restart: always
    healthcheck:
      disable: false
	  
  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:
      - model-cache:/cache
    env_file:
      - .env
    restart: always
    healthcheck:
      disable: false

  redis:
    container_name: immich_redis
    image: docker.io/redis:6.2-alpine@sha256:2d1463258f2764328496376f5d965f20c6a67f66ea2b06dc42af351f75248792
    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:
      # Do not edit the next line. If you want to change the database storage location on your system, edit the value of DB_DATA_LOCATION in the .env file
      - ${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='SELE>      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">    restart: always
volumes:
  model-cache:

You might not want to use the immich-machine-learning. Or if you have another more powerful computer it might be a good idea to put this here. There are some other lines we will add later. Now also create the .env file. I have not modiefied this file yet but will change the upload location later on.

# 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
#UPLOAD_LOCATION=./Immich
# 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=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

Start the containers with “sudo docker compose -d up”. Make sure you do not get any errors. Look in Portainer for the logs. Try to access Immich via http://internalipofyouhost:2283

Back to Swag

In order to access Immich externally we need to add the immich.conf file. Mine is located here:

/srv/docker/swag/config/nginx/site-confs

Create a new file via:

sudo nano immich.conf
server {

    listen       443 ssl;
    listen [::]:443 ssl;
    server_name immich.mydomain.org;
    include /config/nginx/ssl.conf;
    # allow large file uploads
    client_max_body_size 50000M;

    # Set headers
    proxy_set_header Host              $http_host;
    proxy_set_header X-Real-IP         $remote_addr;
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;

    # enable websockets: http://nginx.org/en/docs/http/websocket.html
    proxy_http_version 1.1;
    proxy_set_header   Upgrade    $http_upgrade;
    proxy_set_header   Connection "upgrade";
    proxy_redirect     off;

    # set timeout
    proxy_read_timeout 600s;
    proxy_send_timeout 600s;
    send_timeout       600s;

    location / {
        proxy_pass http://myinternalip:2283/;
    }
}

I had some issues getting this correct. It could be the reason that my Docker compose was not updated and I did some errors in the compose file. Or it could be an issues with networks as Swag and Immich were in different stacks. Anyway I got this error on desktop but not on mobile. Usually this is an error indicating there is some errors with web sockets. I think it was the networking fix that solved it or the fact that I put the static address in the proxy pass above.

Double check that you have an A record in Cloudflare or your dns. Restart Swag. Try to access it via internet now. It should work. So now Immich is up and running. It works via internet and it is time to configure it so we can use it in parallel with Synology photos.

Mounts

The key to get this as good as possible will be mounts. And we want to do this in such a safe way as possible so we do not break something in Synology Photos. We also want to separate uploads from the existing folders. In the examples below we will do some tests. In your case you might want to try this to and later on when this works you can go ahead and mount the shared folders “photo” and “video”. They are default Synology folders. We will add them as Immich external libraries.

NAS

First create a shared folder on your NAS. Disable trashcan. Otherwise Immich will see all images in the trash.

Edit NFS permissions. Enter your host. By default privilege is Read/Write. There is three ways of controlling this.

  • Via Synology NFS rule
  • Via fstab when you mount in Linux
  • Via Docker compose file and volumes

In this test mount we want to be able to write files. We will create the upload folder in this folder later. I have tried to figure out the best Squash setting. You might want to try some other setting here in order to make it more secure. Like make root to admin.

Linux mounts

Back to the host terminal. Now try the following command.

sudo mount 192.168.0.100:/volume1/Immich /mnt/Immich

Put an image in that folder on your nas. Open /mnt on your host and see if you can see the file. If so it is mounted. There are some other commands that may be useful to manage mounts.

  • mount – list all mounts
  • mount | grep nfs – lists the nfs mounts and is more useful for us.
  • mount -a – will try to mount all filesystems we have added in fstab

Fstab

If you reboot your server mounts are lost. We want persistant mounts. This is where fstab comes in. You can run fstab like this:

sudo nano /etc/fstab
192.168.0.100:/volume1/Immich /mnt/Immich nfs rw,auto,noatime,nolock,bg,intr,tcp,actimeo=1800 0 0

The rw setting above is not needed but tells it is a read/write filesystem. This is the second option we had to manage this. There are many settings for fstab. My example above may be incorrect but it works. Note that you will need the full Synology file path with volume1 in my case. Now reboot and make sure it still works after. Check the mnt folder and create files both ways.

Docker compose mounts

We want our containers to be able to access the mounts. In one case we will use it for uploads and later on for external libraries. However it works the same regarding to mounts with the exception that libraries will be read only. Now open docker-compose.yaml for Immich

    volumes:
# Do not edit the next line. If you want to change the media storage location on your system, edit the value of UPLOAD_LOCATION in the .env file
      - /mnt/Immich:/mnt/Immich:rw
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro

The third line will mount our NAS. Notice that it tells rw. This is the third way of managing filesystems. It could be writable in the share, in fstab but restricted here. Save and restart the container. You can see
LIKE sudo docker exec -it immich_server bash

Now open up Immich. Add the mount /mnt/Immich.

This is just a test mount. I did pu some images in here on my nas and made sure they showed up in Immich. They did.

Now we want to add a real folder that exists in my video folder on my Synology. I could add everything but it might be a very bad idéa due to video transcoding. I will get back to this later. Also make sure you read the full docs about External Libraries | Immich.

First share the full videofolder on your nas as we did before. Make it read only. Then I mount this path

sudo mount 192.168.0.100:/volume1/video/Videokamera/fotboll/p08 /mnt/videopmif08

Then add it in fstab if you want it to be persistant. Now add like below in as a new line in your Immich docker compose file. Restart the container and add it like we did before. You can run some commands to make sure that the container has mounted your new folder.

  - /mnt/videomifp08/:/mnt/videomifp08:ro
docker ps
docker inspect -f '{{ .Mounts }}' containerid

The commands above will show you if it is mounted. If not it will not work in Immich. Now in Immich add a new external library or use the old one.

You just as well have used a sub path in your photos folder on your nas but I wanted to test some videos.

Upload folder

I wanted my files to be stored on my NAS and not on my Linux device running my containers. I had limited space here. Another potion would be to put uploads on your server and use Rsync to move them to your NAS on shedule. I have heard some people do that.

Now I will create another Synology shared folder called “immichupload”. With write access. Do not put it in a subdir on your existing mounts. This is same we did before.

Create a mount point on your server with:

sudo mkdir /mnt/immichupload

Mount it with

sudo mount 192.168.0.100:/volume1/immichupload /mnt/immichupload

Add it in fstab like

192.168.0.100:/volume1/immichupload /mnt/immichupload nfs auto,noatime,nolock,bg,intr,tcp,actimeo=1800 0 0

Test it with:

mount -a

Now add the mount in ou docker composefile like before. Restart your container and make sure you have the new upload mount.

- /mnt/immichupload:/mnt/immichupload:rw

It might be a very bad idea to use you nas for uploads. My nas goes to sleepmode and this might cause problems. So make sure this is working as you want before changing this. The last thing we should do is to edit the .env file.

# The location where your uploaded files are stored
## OLD UPLOAD LOCATION###UPLOAD_LOCATION=./library
UPLOAD_LOCATION= /mnt/immichupload

Now restart the containers. try to upload an image. Take at look at your new folder on your nas. Images are now saved here instead.

We also now has far more space. Note that you might want to add other locations for thumbs and videos. You can read more about this here.

One thing I encountered was that I had issues restarting the Immich server after I changed upload location. I believe this was because I had pending video transcoding jobs or that it had issues finding my old files. So I ended up deleting all Immich folders including the database and started from scrath. After this the upload location was set on my nas.

Conclusion

So in this this third post we have setup Immich. I would recommend you to read the docs at their site in order to make the setup correct. Some things might change. I did this tutorial mostly for myself and there might be errors. The official guides might be complicated for non tech users. We have also been able to add external libraries as well as mounted and changed the upload folders. Hopefully this might be helpful for those of you who will use Immich with an Synology NAS. In the last post I told you we were to add authentication. I might save this for later and instead we will look at the pros and cons when it comes to Photos vs Immich.