this post was submitted on 05 Apr 2024
40 points (88.5% liked)

Selfhosted

40394 readers
361 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 2 years ago
MODERATORS
 

Everything was good, great in fact. Everything was working, but my OCD weren't okay with how a few services were set-up, so I cleaned up my yaml, commented my docker compose and felt cushty… right up until it was time to fix Immich.

I have minor beef with Immich and basically any larger project and the way they go about their Docker Compose. Basically I feel they make the assumption that they're the only thing running.

^Disclaimer: I fully accept this is all just me being too stupid and not the Immich development team.

So first things first, let's rename database to immich-database, redis to immich-redis and most importantly, let's give it a port that's not the default postgres port that everyone wants to use. Easy right? Nope.

First Immich said it couldn't find the database, so I went in and added the IP as the DB_URL to the .env. But that didn't really help, so I went back to the Docker Compose and added the path to the references to the env.

Second issue I stumble upon, is that despite the port being available as DB_PORT Immich decided it was a suggestion and not an instruction. No worries, I edit the database URL to include the port.

Okay, I'm on the home stretch now right. I mean this was working before I decided to mess around with it in the name of scalability or whatever I thought was genius at the time… except

[Nest] 7  - 04/05/2024, 6:10:23 PM   ERROR [ExceptionHandler] no PostgreSQL user name specified in startup packet

What does that even mean? Why won't you work? So I do a web search and everything is saying that docker probably isn't reading the username from the env file or the Docker Compose. I try adding single quotes and no joy, double quotes, no joy. I have no idea where I've gone wrong. I feel like my beautiful simple Docker Compose now looks like Frankenstein's Monster. Help 🙏

ENV

# 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=immichlibrary

# 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="RANDOMLIES"
DB_URL=http://192.168.0.89:8765
DB_PORT=8765

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

REDIS_HOSTNAME=immich_redis

Docker Compose

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
      - immichlibrary:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - /opt/immich/.env
    environment:
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: ${DB_DATABASE_NAME}
    ports:
      - 2283:3001
    depends_on:
      - immich-redis
      - immich-database
    restart: always

  immich-microservices:
    container_name: immich_microservices
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    # extends:
    #   file: hwaccel.yml
    #   service: hwaccel
    command: [ "start.sh", "microservices" ]
    volumes:
      #- ${UPLOAD_LOCATION}:/usr/src/app/upload
      - immichlibrary:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - /opt/immich/.env
    environment:
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: ${DB_DATABASE_NAME}
    depends_on:
      - immich-redis
      - immich-database
    restart: always

  immich-machine-learning:
    container_name: immich_machine_learning
    image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
    volumes:
      - model-cache:/cache
    env_file:
      - /opt/immich/.env
    restart: always

  immich-redis:
    container_name: immich_redis
    image: redis:6.2-alpine@sha256:c5a607fb6e1bb15d32bbcf14db22787d19e428d59e31a5da67511b49bb0f1ccc
    restart: always

  immich-database:
    container_name: immich_postgres
    image: tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:90724186f0a3517cf6914295b5ab410db9ce23190a2d9d0b9dd6463e3fa298f0
    env_file:
      - /opt/immich/.env
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
    ports:
      - 8765:5432
    volumes:
      - /opt/immich/postgres:/var/lib/postgresql/data
    restart: always

volumes:
  model-cache:
    driver_opts:
      type: "nfs"
      o: "addr=192.168.0.245,nolock,soft,rw"
      device: ":/mnt/Shared Pictures/.Immich/cache"
  immichlibrary:
    driver_opts:
      type: "nfs"
      o: "addr=192.168.0.245,nolock,soft,rw"
      device: ":/mnt/Shared Pictures/.Immich"

Even if you read this and don't feel you can help or have nothing to add, thanks for sharing your time with me 🥹

you are viewing a single comment's thread
view the rest of the comments
[–] MangoPenguin@lemmy.blahaj.zone 20 points 7 months ago* (last edited 7 months ago) (4 children)

So first things first, let’s rename database to immich-database, redis to immich-redis

Docker compose does this for you, so a service named database becomes immich-database if your compose project is named "immich" by placing it inside a folder by that name. You would have ended up with immich-immich-database

Same goes for your volumes.

most importantly, let’s give it a port that’s not the default postgres port that everyone wants to use. Easy right? Nope.

Since the postgres container is on that specific compose project network, the port is not shared and won't interfere with any other compose projects, so there's no need to change it away from the default. The main thing is each compose project is isolated by itself.

Also get rid of the ports: map for the database, it's already part of the same compose network and does not need a port exposed to the outside.

so I went in and added the IP as the DB_URL to the .env

Don't use IPs to refer to docker containers as they change, instead use the container name so database for example. (Just don't prefix it with the project name, so don't use immich-database for example).

Essentially just undo your changes and it should all work as expected, and will be entirely isolated so won't interfere with any other containers or compose projects you run.

[–] sabreW4K3@lazysoci.al 5 points 7 months ago (3 children)

Thanks for the info. In my head, I had one eye on the future, because honestly, when I chuck it in the corner, I know myself, I won't be arsed enough to jump from directory to directory to run the individual compose files and so I'm kinda aiming to have everything run from a single docker compose. Am I being naive?

[–] avidamoeba@lemmy.ca 6 points 7 months ago* (last edited 7 months ago) (1 children)

Definitely don't put everything in a single docker-compose file. For one compose files change from the developer to add/adjust things. You want to make updating to the latest one as easy as copying it over the existing one with minor changes if any, ideally none. For another, you shouldn't rely on running any of it manually. If you want to chuck it in a corner, write some systemd unit files to start and restart the docker compose services for you. Finally, it's not too difficult to find what compose files you have once you've forgotten them. Use docker compose ls, plain docker and if all else fails find, grep, ps. Also you can always write what you did and how to find it in a README.md file. Print it and stick it to the box if you have to. The point is to leave breadcrumbs and be able to follow them, not remember shit you can't possibly remember for a long time.

Read more about docker and compose. They're extremely powerful and some of the most important tools out there. They're also very easy to use but you can't just figure them out beyond the absolute basics, you have to RTFM for how to do things. If something looks difficult, read to see what's the best way to do it. Chances are it isn't. At some point you'd be wondering how you've lived without docker. 😂

[–] sabreW4K3@lazysoci.al 4 points 7 months ago

I love this community. Thank you so much.

load more comments (1 replies)
load more comments (1 replies)