[BUG] immich_server and microservices can't connect to DB #1477

Closed
opened 2026-02-05 02:01:23 +03:00 by OVERLORD · 8 comments
Owner

Originally created by @darkra66it on GitHub (Oct 18, 2023).

The bug

Using almost-vanilla configuration as per the wiki, I've not been able to get this deployed via the docker compose method.

When checking container status, immich_server and immich_microservices are crashing/restarting constantly, so I'm not able to access the web portal.

Diving deeper, the docker logs for immich_server and immich_microservices show connection timeouts for both the redis and postgres DB (but mostly the redis) like:

[Nest] 7 - 10/18/2023, 8:22:58 PM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (8)...
Error: Connection terminated due to connection timeout
at Connection. (/usr/src/app/node_modules/pg/lib/client.js:132:73)
at Object.onceWrapper (node:events:628:28)
at Connection.emit (node:events:514:28)
at Socket. (/usr/src/app/node_modules/pg/lib/connection.js:63:12)
at Socket.emit (node:events:514:28)
at TCP. (node:net:337:12)
Error: connect EHOSTUNREACH 172.18.0.6:6379
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) {
errno: -113,
code: 'EHOSTUNREACH',
syscall: 'connect',
address: '172.18.0.6',
port: 6379
}

Checking logs for redis, last message "ready to accept connections"

Checking logs for postgres, last message: "database system is ready to accept connections"

The OS that Immich Server is running on

Ubuntu 18.04 ARM64

Version of Immich Server

latest

Version of Immich Mobile App

n/a

Platform with the issue

  • Server
  • Web
  • Mobile

Your docker-compose.yml content

version: "3.8"

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
    depends_on:
      - redis
      - database
      - typesense
    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
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    depends_on:
      - redis
      - database
      - typesense
    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:
      - .env
    restart: always

  immich-web:
    container_name: immich_web
    image: ghcr.io/immich-app/immich-web:${IMMICH_VERSION:-release}
    env_file:
      - .env
    restart: always

  typesense:
    container_name: immich_typesense
    image: typesense/typesense:0.24.1@sha256:9bcff2b829f12074426ca044b56160ca9d777a0c488303469143dd9f8259d4dd
    environment:
      - TYPESENSE_API_KEY=${TYPESENSE_API_KEY}
      - TYPESENSE_DATA_DIR=/data
      # remove this to get debug messages
      - GLOG_minloglevel=1
    volumes:
      - tsdata:/data
    restart: always

  redis:
    container_name: immich_redis
    image: redis:6.2-alpine@sha256:70a7a5b641117670beae0d80658430853896b5ef269ccf00d1827427e3263fa3
    restart: always

  database:
    container_name: immich_postgres
    image: postgres:14-alpine@sha256:28407a9961e76f2d285dc6991e8e48893503cc3836a4755bbc2d40bcc272a441
    env_file:
      - .env
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
    volumes:
      - pgdata:/var/lib/postgresql/data
    restart: always

  immich-proxy:
    container_name: immich_proxy
    image: ghcr.io/immich-app/immich-proxy:${IMMICH_VERSION:-release}
    environment:
      # Make sure these values get passed through from the env file
      - IMMICH_SERVER_URL
      - IMMICH_WEB_URL
    ports:
      - 2283:8080
    depends_on:
      - immich-server
      - immich-web
    restart: always

volumes:
  pgdata:
  model-cache:
  tsdata:

Your .env content

# 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=/home/ubuntu/immich-app/uploads

# The Immich version to use. You can pin this to a specific version like "v1.71.0"
IMMICH_VERSION=release

# Connection secrets for postgres and typesense. You should change these to random passwords
TYPESENSE_API_KEY=some-random-text
DB_PASSWORD=postgres

# 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

Reproduction steps

1. download sample config files
2. change upload_location in .env
3. docker compose up -d
4. docker compose down and then up again

Additional information

No response

Originally created by @darkra66it on GitHub (Oct 18, 2023). ### The bug Using almost-vanilla configuration as per the wiki, I've not been able to get this deployed via the docker compose method. When checking container status, immich_server and immich_microservices are crashing/restarting constantly, so I'm not able to access the web portal. Diving deeper, the docker logs for immich_server and immich_microservices show connection timeouts for both the redis and postgres DB (but mostly the redis) like: [Nest] 7 - 10/18/2023, 8:22:58 PM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (8)... Error: Connection terminated due to connection timeout at Connection.<anonymous> (/usr/src/app/node_modules/pg/lib/client.js:132:73) at Object.onceWrapper (node:events:628:28) at Connection.emit (node:events:514:28) at Socket.<anonymous> (/usr/src/app/node_modules/pg/lib/connection.js:63:12) at Socket.emit (node:events:514:28) at TCP.<anonymous> (node:net:337:12) Error: connect EHOSTUNREACH 172.18.0.6:6379 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) { errno: -113, code: 'EHOSTUNREACH', syscall: 'connect', address: '172.18.0.6', port: 6379 } Checking logs for redis, last message "ready to accept connections" Checking logs for postgres, last message: "database system is ready to accept connections" ### The OS that Immich Server is running on Ubuntu 18.04 ARM64 ### Version of Immich Server latest ### Version of Immich Mobile App n/a ### Platform with the issue - [X] Server - [ ] Web - [ ] Mobile ### Your docker-compose.yml content ```YAML version: "3.8" 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 depends_on: - redis - database - typesense 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 - /etc/localtime:/etc/localtime:ro env_file: - .env depends_on: - redis - database - typesense 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: - .env restart: always immich-web: container_name: immich_web image: ghcr.io/immich-app/immich-web:${IMMICH_VERSION:-release} env_file: - .env restart: always typesense: container_name: immich_typesense image: typesense/typesense:0.24.1@sha256:9bcff2b829f12074426ca044b56160ca9d777a0c488303469143dd9f8259d4dd environment: - TYPESENSE_API_KEY=${TYPESENSE_API_KEY} - TYPESENSE_DATA_DIR=/data # remove this to get debug messages - GLOG_minloglevel=1 volumes: - tsdata:/data restart: always redis: container_name: immich_redis image: redis:6.2-alpine@sha256:70a7a5b641117670beae0d80658430853896b5ef269ccf00d1827427e3263fa3 restart: always database: container_name: immich_postgres image: postgres:14-alpine@sha256:28407a9961e76f2d285dc6991e8e48893503cc3836a4755bbc2d40bcc272a441 env_file: - .env environment: POSTGRES_PASSWORD: ${DB_PASSWORD} POSTGRES_USER: ${DB_USERNAME} POSTGRES_DB: ${DB_DATABASE_NAME} volumes: - pgdata:/var/lib/postgresql/data restart: always immich-proxy: container_name: immich_proxy image: ghcr.io/immich-app/immich-proxy:${IMMICH_VERSION:-release} environment: # Make sure these values get passed through from the env file - IMMICH_SERVER_URL - IMMICH_WEB_URL ports: - 2283:8080 depends_on: - immich-server - immich-web restart: always volumes: pgdata: model-cache: tsdata: ``` ### Your .env content ```Shell # 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=/home/ubuntu/immich-app/uploads # The Immich version to use. You can pin this to a specific version like "v1.71.0" IMMICH_VERSION=release # Connection secrets for postgres and typesense. You should change these to random passwords TYPESENSE_API_KEY=some-random-text DB_PASSWORD=postgres # 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 ``` ### Reproduction steps ```bash 1. download sample config files 2. change upload_location in .env 3. docker compose up -d 4. docker compose down and then up again ``` ### Additional information _No response_
Author
Owner

@jrasm91 commented on GitHub (Oct 19, 2023):

So you have any networking things going on? If your run docker compose up database redis do they come up correctly?

@jrasm91 commented on GitHub (Oct 19, 2023): So you have any networking things going on? If your run docker compose up database redis do they come up correctly?
Author
Owner

@darkra66it commented on GitHub (Oct 19, 2023):

So you have any networking things going on? If your run docker compose up database redis do they come up correctly?

I'm new to Docker / Docker networking so not sure where to start troubleshooting.

ubuntu@immich-ubuntu-arm64:~/immich-app$ sudo docker compose up -d
[+] Running 9/9
✔ Network immich-app_default Created 0.0s
✔ Container immich_web Started 0.9s
✔ Container immich_redis Started 0.8s
✔ Container immich_typesense Started 1.0s
✔ Container immich_machine_learning Started 0.8s
✔ Container immich_postgres Started 0.4s
✔ Container immich_microservices Started 1.5s
✔ Container immich_server Started 1.4s
✔ Container immich_proxy Started 1.8s

From searching around, my guess is that there is something blocking the inter-container traffic?

immich_server | [Nest] 7 - 10/18/2023, 10:51:04 PM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (9)...
immich_server | Error: connect EHOSTUNREACH 172.21.0.2:5432
immich_server | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
immich_server | [Nest] 7 - 10/18/2023, 10:51:04 PM ERROR [ExceptionHandler] connect EHOSTUNREACH 172.21.0.2:5432
immich_server | Error: connect EHOSTUNREACH 172.21.0.2:5432
immich_server | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
immich_microservices | Error: connect EHOSTUNREACH 172.21.0.3:6379
immich_microservices | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) {
immich_microservices | errno: -113,
immich_microservices | code: 'EHOSTUNREACH',
immich_microservices | syscall: 'connect',
immich_microservices | address: '172.21.0.3',
immich_microservices | port: 6379
immich_microservices | }

@darkra66it commented on GitHub (Oct 19, 2023): > So you have any networking things going on? If your run docker compose up database redis do they come up correctly? I'm new to Docker / Docker networking so not sure where to start troubleshooting. ubuntu@immich-ubuntu-arm64:~/immich-app$ sudo docker compose up -d [+] Running 9/9 ✔ Network immich-app_default Created 0.0s ✔ Container immich_web Started 0.9s ✔ Container immich_redis Started 0.8s ✔ Container immich_typesense Started 1.0s ✔ Container immich_machine_learning Started 0.8s ✔ Container immich_postgres Started 0.4s ✔ Container immich_microservices Started 1.5s ✔ Container immich_server Started 1.4s ✔ Container immich_proxy Started 1.8s From searching around, my guess is that there is something blocking the inter-container traffic? immich_server | [Nest] 7 - 10/18/2023, 10:51:04 PM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (9)... immich_server | Error: connect EHOSTUNREACH 172.21.0.2:5432 immich_server | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) immich_server | [Nest] 7 - 10/18/2023, 10:51:04 PM ERROR [ExceptionHandler] connect EHOSTUNREACH 172.21.0.2:5432 immich_server | Error: connect EHOSTUNREACH 172.21.0.2:5432 immich_server | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) immich_microservices | Error: connect EHOSTUNREACH 172.21.0.3:6379 immich_microservices | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) { immich_microservices | errno: -113, immich_microservices | code: 'EHOSTUNREACH', immich_microservices | syscall: 'connect', immich_microservices | address: '172.21.0.3', immich_microservices | port: 6379 immich_microservices | }
Author
Owner

@darkra66it commented on GitHub (Oct 19, 2023):

Ok, I've been able to resolve this -- it appears that installing docker using snap is a bad idea.

I ran sudo snap remove docker --purge to wipe it out completely. Then I installed docker via https://docs.docker.com/engine/install/ubuntu/ and rebuilt everything from scratch.

sudo docker compose up -d now works as expected, I can login and start experimenting.

@darkra66it commented on GitHub (Oct 19, 2023): Ok, I've been able to resolve this -- it appears that installing docker using `snap `is a bad idea. I ran `sudo snap remove docker --purge` to wipe it out completely. Then I installed docker via https://docs.docker.com/engine/install/ubuntu/ and rebuilt everything from scratch. `sudo docker compose up -d` now works as expected, I can login and start experimenting.
Author
Owner

@Devqon commented on GitHub (Dec 25, 2023):

I had the same issue when installing Immich with docker-compose on my Synology NAS. Guess it is related to the firewall issues mentioned above. A restart of the NAS seems to have fixed it (only disabling and re-enabling the firewall did not work).

Can anybody explain why this happens? It also only happens with Immich, and it happened on all my tries consistently

@Devqon commented on GitHub (Dec 25, 2023): I had the same issue when installing Immich with docker-compose on my Synology NAS. Guess it is related to the firewall issues mentioned above. A restart of the NAS seems to have fixed it (only disabling and re-enabling the firewall did not work). Can anybody explain why this happens? It also only happens with Immich, and it happened on all my tries consistently
Author
Owner

@ihavenokia commented on GitHub (Jan 31, 2024):

I'm running a ubuntu server, with a lot of containers working fine, but I'm getting this message when running immich stack (portainer compose or terminal). I've tried to use a db server that I use for other apps, but changing that didn't help. Any ideias what might be blocking this?

@ihavenokia commented on GitHub (Jan 31, 2024): I'm running a ubuntu server, with a lot of containers working fine, but I'm getting this message when running immich stack (portainer compose or terminal). I've tried to use a db server that I use for other apps, but changing that didn't help. Any ideias what might be blocking this?
Author
Owner

@gregwym commented on GitHub (Sep 11, 2024):

Thanks @Devqon , it's indeed a firewall issue.

For anyone who's using Immich on Synology NAS, rather than turning off firewall entirely, you need to allow the immich_default network subnet to access other ports through the firewall. (You may use more specific ports to make it more secure.)

  1. Build the Immich docker compose project
  2. Go to Container Manger -> Network -> expand immich_default and write down the subnet.
  3. Go to Control Panel -> Security -> Firewall -> Edit Rules
  4. Add a new rule
    • Ports: All
    • Source IP: Specific IP
      • Choose Subnet
      • IP address: the immich_default subnet value without /16
      • Subnet mask: 255.255.0.0
    • Action: Allow
    • save the rules

Please see my rules as an example.
image

@gregwym commented on GitHub (Sep 11, 2024): Thanks @Devqon , it's indeed a firewall issue. For anyone who's using Immich on Synology NAS, rather than turning off firewall entirely, you need to allow the `immich_default` network subnet to access other ports through the firewall. (You may use more specific ports to make it more secure.) 1. Build the Immich docker compose project 1. Go to Container Manger -> Network -> expand `immich_default` and write down the subnet. 1. Go to Control Panel -> Security -> Firewall -> Edit Rules 1. Add a new rule * Ports: All * Source IP: Specific IP * Choose `Subnet` * IP address: the `immich_default` subnet value without `/16` * Subnet mask: `255.255.0.0` * Action: Allow * save the rules Please see my rules as an example. ![image](https://github.com/user-attachments/assets/87e0a69c-737e-40e8-a67b-4af10cdc22eb)
Author
Owner

@p3rb3r commented on GitHub (Oct 4, 2024):

Thanks @Devqon , it's indeed a firewall issue.

For anyone who's using Immich on Synology NAS, rather than turning off firewall entirely, you need to allow the immich_default network subnet to access other ports through the firewall. (You may use more specific ports to make it more secure.)

1. Build the Immich docker compose project

2. Go to Container Manger -> Network -> expand `immich_default` and write down the subnet.

3. Go to Control Panel -> Security -> Firewall -> Edit Rules

4. Add a new rule
   
   * Ports: All
   * Source IP: Specific IP
     
     * Choose `Subnet`
     * IP address: the `immich_default` subnet value without `/16`
     * Subnet mask: `255.255.0.0`
   * Action: Allow
   * save the rules

Please see my rules as an example. image

Confirm as a fix. Seen people asking about this for ages well done

@p3rb3r commented on GitHub (Oct 4, 2024): > Thanks @Devqon , it's indeed a firewall issue. > > For anyone who's using Immich on Synology NAS, rather than turning off firewall entirely, you need to allow the `immich_default` network subnet to access other ports through the firewall. (You may use more specific ports to make it more secure.) > > 1. Build the Immich docker compose project > > 2. Go to Container Manger -> Network -> expand `immich_default` and write down the subnet. > > 3. Go to Control Panel -> Security -> Firewall -> Edit Rules > > 4. Add a new rule > > * Ports: All > * Source IP: Specific IP > > * Choose `Subnet` > * IP address: the `immich_default` subnet value without `/16` > * Subnet mask: `255.255.0.0` > * Action: Allow > * save the rules > > > Please see my rules as an example. ![image](https://private-user-images.githubusercontent.com/510089/366162518-87e0a69c-737e-40e8-a67b-4af10cdc22eb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjgwNTEzNzAsIm5iZiI6MTcyODA1MTA3MCwicGF0aCI6Ii81MTAwODkvMzY2MTYyNTE4LTg3ZTBhNjljLTczN2UtNDBlOC1hNjdiLTRhZjEwY2RjMjJlYi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQxMDA0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MTAwNFQxNDExMTBaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT03N2ExNmVkMjc5MDIwNWU5NjAxMTgzYmUxNTU4ZmFjZDIyYzhlMjVkZGVjODdiMGVmNTdlMGEzYzdhYjA1MDE3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.xVt_mv2ULeX2XBE_SgNm0UoAK0awsxnHuoTxRqEbXLo) Confirm as a fix. Seen people asking about this for ages well done
Author
Owner

@sophuric commented on GitHub (Nov 2, 2024):

Hi, I have the same issue, what rules should I use for ufw?

@sophuric commented on GitHub (Nov 2, 2024): Hi, I have the same issue, what rules should I use for `ufw`?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#1477