ScaleTail icon indicating copy to clipboard operation
ScaleTail copied to clipboard

🐞 Bug: Immich service failing database connection

Open norey opened this issue 6 months ago • 10 comments

Bug Description

All the containers in the Immich stack come up except for the main one: app-${SERVICE}-server, it's failing with:

[app-immich-server] 2026-05-24T22:02:47.442325026Z Node.js v24.14.1
[app-immich-server] 2026-05-24T22:03:38.741846578Z Initializing Immich v2.7.5
[app-immich-server] 2026-05-24T22:03:38.747900514Z Detected CPU Cores: 16
[app-immich-server] 2026-05-24T22:03:39.933416295Z (node:7) ExperimentalWarning: WASI is an experimental feature and might change at any time
[app-immich-server] 2026-05-24T22:03:39.933449882Z (Use `node --trace-warnings ...` to show where the warning was created)
[app-immich-server] 2026-05-24T22:03:39.960166499Z node:internal/process/promises:394
[app-immich-server] 2026-05-24T22:03:39.960184263Z     triggerUncaughtException(err, true /* fromPromise */);
[app-immich-server] 2026-05-24T22:03:39.960186134Z     ^
[app-immich-server] 2026-05-24T22:03:39.960187644Z 
[app-immich-server] 2026-05-24T22:03:39.960189100Z Error: getaddrinfo ENOTFOUND database
[app-immich-server] 2026-05-24T22:03:39.960190662Z     at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:122:26) {
[app-immich-server] 2026-05-24T22:03:39.960192251Z   errno: -3008,
[app-immich-server] 2026-05-24T22:03:39.960193747Z   code: 'ENOTFOUND',
[app-immich-server] 2026-05-24T22:03:39.960195219Z   syscall: 'getaddrinfo',
[app-immich-server] 2026-05-24T22:03:39.960196666Z   hostname: 'database'
[app-immich-server] 2026-05-24T22:03:39.960198149Z }
[app-immich-server] 2026-05-24T22:03:39.960199559Z 
[app-immich-server] 2026-05-24T22:03:39.960200972Z Node.js v24.14.1
[app-immich-server] 2026-05-24T22:04:40.083079285Z Initializing Immich v2.7.5
[app-immich-server] 2026-05-24T22:04:40.089008410Z Detected CPU Cores: 16
[app-immich-server] 2026-05-24T22:04:41.262146145Z (node:7) ExperimentalWarning: WASI is an experimental feature and might change at any time
[app-immich-server] 2026-05-24T22:04:41.262162803Z (Use `node --trace-warnings ...` to show where the warning was created)
[app-immich-server] 2026-05-24T22:04:41.287359013Z node:internal/process/promises:394
[app-immich-server] 2026-05-24T22:04:41.287370773Z     triggerUncaughtException(err, true /* fromPromise */);
[app-immich-server] 2026-05-24T22:04:41.287373656Z     ^
[app-immich-server] 2026-05-24T22:04:41.287375344Z 
[app-immich-server] 2026-05-24T22:04:41.287376912Z Error: getaddrinfo ENOTFOUND database
[app-immich-server] 2026-05-24T22:04:41.287383778Z     at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:122:26) {
[app-immich-server] 2026-05-24T22:04:41.287385468Z   errno: -3008,
[app-immich-server] 2026-05-24T22:04:41.287396842Z   code: 'ENOTFOUND',
[app-immich-server] 2026-05-24T22:04:41.287398436Z   syscall: 'getaddrinfo',
[app-immich-server] 2026-05-24T22:04:41.287399993Z   hostname: 'database'
[app-immich-server] 2026-05-24T22:04:41.287401587Z }

Can't figure it out. Is it because database isn't in the same network?

Expected Behavior

A running container

Actual Behavior

Failing with


Error: getaddrinfo ENOTFOUND database
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:122:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'database'
}

Screenshots

No response

Operating System

Linux

Tailscale Version

latest

Docker Version

29.4.2

Relevant Logs or Error Messages


Docker Compose Configuration


Environment Configuration (.env file)


Additional Context

No response

norey avatar May 24 '26 23:05 norey

edit: ai translation to proper english Same issue here, fixed with two changes to compose.yml.

Root cause: network_mode: service:tailscale isolates the application container inside the Tailscale container's network namespace. Two consequences:

  1. database and redis are not on the same Docker network as application — they are on Compose's default network, unreachable from the Tailscale namespace
  2. Tailscale with TS_ACCEPT_DNS=true (default) overwrites /etc/resolv.conf with MagicDNS only (100.100.100.100) — Docker DNS (127.0.0.11) is removed, so Compose service names like database/redis can no longer be resolved

Fix:

1. Add a custom bridge network

services:
  tailscale:
    networks:
      - immich-net
  database:
    networks:
      - immich-net
  redis:
    networks:
      - immich-net
  immich-machine-learning:
    networks:
      - immich-net
  # application doesn't need networks:
  # it inherits via network_mode: service:tailscale

networks:
  immich-net:
    driver: bridge
2. Prevent Tailscale from overwriting DNS while keeping MagicDNS
  tailscale:
    environment:
      - TS_ACCEPT_DNS=false
    dns:
      - 100.100.100.100   # MagicDNS (TailNet hostname resolution)
      - 127.0.0.11        # Docker DNS (service name resolution)
With TS_ACCEPT_DNS=false, Tailscale no longer modifies /etc/resolv.conf. Docker DNS (127.0.0.11) acts as a proxy to MagicDNS, so both work:
database                  → 172.19.0.3   ✓
my-server.tailnet.ts.net  → 100.x.x.x   ✓

Baniel83 avatar Jun 26 '26 08:06 Baniel83

Alternative cleaner solution: set TS_USERSPACE=true on the tailscale container.

This approach is used in the Alex's Tailscale video snippet:
https://github.com/tailscale-dev/video-code-snippets/blob/main/2025/2025-06-self-hosting-part2/immich/compose.yaml

  tailscale:
    environment:
      - TS_USERSPACE=true
With TS_USERSPACE=false (default), Tailscale creates a kernel TUN device and overwrites /etc/resolv.conf with MagicDNS only — Docker DNS (127.0.0.11) is removed, so Compose service names like database/redis can no longer be resolved.
With TS_USERSPACE=true, Tailscale runs in userspace networking mode — it doesn't touch /etc/resolv.conf, doesn't need cap_add: net_admin or /dev/net/tun. Docker DNS stays intact, and the application container (sharing the network via network_mode: service:tailscale) can resolve all Compose service names normally.

Baniel83 avatar Jun 26 '26 08:06 Baniel83

I got this fixed using Alex's env variables:

environment:
      DB_HOSTNAME: immich-database
      DB_PASSWORD: tailscale123
      DB_USERNAME: zaphod
      DB_DATABASE_NAME: immich
      REDIS_HOSTNAME: immich-redis

My understanding was that the Immich containers use the hardcoded database service to connect to it. So when the service name is different, it fails to connect and spits out that error. Fixing it here was by forcing it to use the service name DB_HOSTNAME: immich-database

norey avatar Jun 26 '26 14:06 norey

Hm, I'm not able to reproduce the issue. Just used the following configuration, and it starts up just fine.

$ cat compose.yaml 
configs:
  ts-serve:
    content: |
      {"TCP":{"443":{"HTTPS":true}},
      "Web":{"$${TS_CERT_DOMAIN}:443":
          {"Handlers":{"/":
          {"Proxy":"http://127.0.0.1:2283"}}}},
      "AllowFunnel":{"$${TS_CERT_DOMAIN}:443":false}}

services:
# Make sure you have updated/checked the .env file with the correct variables. 
# All the ${ xx } need to be defined there.
  # Tailscale Sidecar Configuration
  tailscale:
    image: tailscale/tailscale:latest # Image to be used
    container_name: tailscale-${SERVICE} # Name for local container management
    hostname: ${SERVICE} # Name used within your Tailscale environment
    environment:
      #- TS_AUTHKEY=${TS_AUTHKEY}
      - TS_STATE_DIR=/var/lib/tailscale
      - TS_SERVE_CONFIG=/config/serve.json # Tailscale Serve configuration to expose the web interface on your local Tailnet - remove this line if not required
      - TS_USERSPACE=false
      - TS_ENABLE_HEALTH_CHECK=true              # Enable healthcheck endpoint: "/healthz"
      - TS_LOCAL_ADDR_PORT=127.0.0.1:41234       # The <addr>:<port> for the healthz endpoint
      #- TS_ACCEPT_DNS=true # Uncomment when using MagicDNS
    configs:
      - source: ts-serve
        target: /config/serve.json
    volumes:
      - ./config:/config # Config folder used to store Tailscale files - you may need to change the path
      - ./ts/state:/var/lib/tailscale # Tailscale requirement - you may need to change the path
    devices:
      - /dev/net/tun:/dev/net/tun # Network configuration for Tailscale to work
    cap_add:
      - net_admin # Tailscale requirement
    #ports:
    #  - 0.0.0.0:${SERVICEPORT}:${SERVICEPORT} # Binding port ${SERVICE}PORT to the local network - may be removed if only exposure to your Tailnet is required
    # If any DNS issues arise, use your preferred DNS provider by uncommenting the config below
    #dns: 
    #  - ${DNS_SERVER}
    healthcheck:
      test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:41234/healthz"] # Check Tailscale has a Tailnet IP and is operational
      interval: 1m # How often to perform the check
      timeout: 10s # Time to wait for the check to succeed
      retries: 3 # Number of retries before marking as unhealthy
      start_period: 10s # Time to wait before starting health checks
    restart: always

  # ${SERVICE}
  application:
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    network_mode: service:tailscale # Sidecar configuration to route ${SERVICE} through Tailscale
    container_name: app-${SERVICE}-server # Name for local container management
    # 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
      - /mnt/data-storage/immich:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    # ports:
    #   - '2283:2283'
    depends_on:
      redis:
        condition: service_healthy
      database:
        condition: service_healthy
      tailscale:
        condition: service_healthy
    restart: always
    healthcheck:
      disable: false

  immich-machine-learning:
    container_name: app-${SERVICE}-machine-learning
    # For hardware acceleration, add one of -[armnn, cuda, rocm, openvino, rknn] 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, rocm, openvino, openvino-wsl, rknn] for accelerated inference - use the `-wsl` version for WSL2 where applicable
    volumes:
      - ./${SERVICE}-data/model-cache:/cache
    env_file:
      - .env
    restart: always
    healthcheck:
      disable: false

  redis:
    container_name: app-${SERVICE}-redis
    image: docker.io/valkey/valkey:9@sha256:3eeb09785cd61ec8e3be35f8804c8892080f3ca21934d628abc24ee4ed1698f6
    #image: docker.io/valkey/valkey:8-bookworm@sha256:fec42f399876eb6faf9e008570597741c87ff7662a54185593e74b09ce83d177
    healthcheck:
      test: redis-cli ping || exit 1
    restart: always

  database:
    container_name: app-${SERVICE}-postgres
    image: ghcr.io/immich-app/postgres:14-vectorchord0.4.3-pgvectors0.2.0@sha256:bcf63357191b76a916ae5eb93464d65c07511da41e3bf7a8416db519b40b1c23
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      POSTGRES_INITDB_ARGS: "--data-checksums"
      # Uncomment the DB_STORAGE_TYPE: 'HDD' var if your database isn't stored on SSDs
      # DB_STORAGE_TYPE: 'HDD'
    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
      - ./${SERVICE}-data/database:/var/lib/postgresql/data
    restart: always
$ cat .env 
#version=1.1
#URL=https://github.com/tailscale-dev/ScaleTail
#COMPOSE_PROJECT_NAME= # Optional: only use when running multiple deployments on the same infrastructure.

# Service Configuration
SERVICE=foto
#IMAGE_URL= # Docker image URL from container registry (e.g., adguard/adguard-home).

# Network Configuration
SERVICEPORT=2283
DNS_SERVER=9.9.9.9

# Tailscale Configuration
#TS_AUTHKEY=

# Custom Immich - https://immich.app/docs/install/docker-compose

# You can find documentation for all the supported env variables at https://immich.app/docs/install/environment-variables
# Optional Service variables
# PUID=1000

# 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=Europe/Amsterdam

# 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

Can you give the above config a go?

crypt0rr avatar Jun 27 '26 18:06 crypt0rr

I have been encountering the same issue. I have the same config, except the volume paths are different, and I uncommented

      - TS_ACCEPT_DNS=true # Uncomment when using MagicDNS

because I have MagicDNS enabled. Could this be why the bug does not appear for you, @crypt0rr? I also uncommented

#ports:
    #  - 0.0.0.0:${SERVICEPORT}:${SERVICEPORT} # Binding port ${SERVICE}PORT to the local network - may be removed if only exposure to your Tailnet is required

just to try but I suspect that is not relevant (and did not help with the issue).

Using Alex's env variables as @norey mentioned did not work for me but setting TS_USERSPACE=true as @Baniel83 suggested worked. I am not an expert on this so I would like to know if this is a reasonable solution or if it is undesirable for some other reason.

stefano-ronchi avatar Jun 27 '26 22:06 stefano-ronchi

I have MagicDNS enabled for my Tailnet as well. But I also force override DNS servers (via the Admin GUI). The TS_USERSPACE=true variable does not change the behaviour on my side (tested just now)

crypt0rr avatar Jun 28 '26 11:06 crypt0rr

@crypt0rr try it with a different name for the database service, replace database: with something else.

norey avatar Jun 28 '26 17:06 norey

Thanks all. There are two separate causes in this thread that produce the same error. I reproduced the first one with the Immich stack on a real Tailnet.

1. TS_ACCEPT_DNS=true is set. The application container shares the Tailscale container's network namespace, including /etc/resolv.conf. With TS_ACCEPT_DNS=true, Tailscale replaces Docker's DNS (127.0.0.11) with MagicDNS (100.100.100.100), which can't resolve Compose service names like database, redis, or immich-machine-learning. That is why it could not be reproduced with the default config: the line is commented out there. The comment next to it ("Uncomment when using MagicDNS") was misleading, sorry about that.

You don't need TS_ACCEPT_DNS to reach Immich at https://immich.<tailnet>.ts.net. It only matters if the Immich container itself must look up other Tailnet devices by name, such as an OAuth provider or SMTP server.

  • If you don't need that: leave TS_ACCEPT_DNS commented out. Nothing else changes.

  • If you do: keep TS_ACCEPT_DNS off and give Docker's DNS MagicDNS as its upstream instead, on the tailscale service:

        dns:
          - 100.100.100.100
        #dns_search:
        #  - <your-tailnet>.ts.net # Only needed for short names
    

    Docker keeps resolving the service names and forwards everything else to MagicDNS. No extra network is required; the default Compose network already works.

@stefano-ronchi TS_USERSPACE=true works because in userspace mode Tailscale doesn't manage resolv.conf. It is fine if Immich only needs to be reached over the Tailnet. The trade-off is that the Immich container can no longer open connections to other Tailnet devices, and traffic goes through the userspace network stack instead of the kernel one.

2. Renamed services. @norey Immich connects to the hostnames database and redis by default. If the services are named differently, as in the video snippet, set DB_HOSTNAME and REDIS_HOSTNAME to match, as you did. With the unmodified ScaleTail compose file the names already match.

What I tested:

Scenario Immich starts database / redis resolve
Default (TS_ACCEPT_DNS commented out) yes yes
TS_ACCEPT_DNS=true no, ENOTFOUND database no
TS_ACCEPT_DNS off, dns: 100.100.100.100 yes, MagicDNS names resolve too yes
TS_USERSPACE=true, TS_ACCEPT_DNS=true yes yes

#351 rewords the comment in every service, adds these notes to the Immich README, and fixes NetBox, which shipped with the setting enabled. This issue closes when it merges. Please reopen if you still see the error with TS_ACCEPT_DNS commented out.

jackspiering avatar Oct 01 '26 19:10 jackspiering

@jackspiering Thank you for the detailed explanation. I am not having the issue anymore even after reverting to the suggested configuration with TS_ACCEPT_DNS off. However I started having a related issue where Immich could not reach the remote machine learning container I set up on a different machine. This was pointed out in the tailscale container logs as

open-conn-track: flow TCP 100.xxx.xxx.xxx:48360 > 100.yyy.yyy.yyy:3003 rejected due to acl

Maybe it is worth adding a note to the README with a suggested secure change to the ACL (I am not certain mine is the way to go) that allows remote machine learning. I am happy to open a new issue if necessary.

stefano-ronchi avatar Oct 03 '26 19:10 stefano-ronchi

Glad the original issue is solved. The new error is your tailnet policy rather than the compose file: the Immich node isn't allowed to connect to the machine learning host on port 3003. A narrow grant is enough, for example:

{
  "src": ["tag:immich"],
  "dst": ["tag:immich-ml"],
  "ip":  ["tcp:3003"]
}

Replace the tags with whatever identifies your two nodes. Two things to check alongside it: keep TS_USERSPACE=false (the default), since Immich needs to open outbound connections to the Tailnet, and either use the ML host's 100.x address in the machine learning URL or add dns: 100.100.100.100 to the tailscale service so the MagicDNS name resolves.

No need for a new issue; I'll add a note on remote machine learning to the Immich README.

jackspiering avatar Oct 03 '26 23:10 jackspiering