Immich Server repeatedly fails with getaddrinfo EAI_AGAIN database even after correct Docker compose and clean setup (WSL2 + Docker Desktop)

I am facing an issue where the Immich server container keeps failing with:

Error: getaddrinfo EAI_AGAIN database
hostname: ‘database’

Even though my Docker compose file is configured correctly with:

DATABASE_HOST=postgres
DATABASE_PORT=5432

and there is no reference to “database” anywhere in my compose or .env file.

System Setup:

  • Windows 10/11
  • Docker Desktop using WSL2 backend
  • WSL2 Ubuntu-20.04
  • Running docker compose inside ~/immich as user “giri”

All containers start normally:

postgres Up
redis Up
immich_server Up (health: starting → crash loop)
immich_web Up
immich_ml Up

But Immich server keeps restarting with DNS resolution errors.

Full Error:
Error: getaddrinfo EAI_AGAIN database
errno: -3001
code: ‘EAI_AGAIN’
syscall: ‘getaddrinfo’
hostname: ‘database’

Environment inside the container (output of printenv):
DATABASE_URL=postgresql://immich:ImmichDBPass123@postgres:5432/immich

The URL is correct, but the server still tries to resolve the hostname “database”.

It looks like some old internal default environment variable such as DATABASE_HOST=database is still being used even after deleting all containers and images.

docker-compose.yml (simplified):

services:
  postgres:
    image: postgres:15
    environment:
      POSTGRES_USER=${POSTGRES_USER}
      POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      POSTGRES_DB=${POSTGRES_DB}

  redis:
    image: redis:7
    command=["redis-server","--requirepass","${REDIS_PASSWORD}"]

  immich-server:
    image: ghcr.io/immich-app/immich-server:release
    environment:
      DATABASE_HOST=postgres
      DATABASE_PORT=5432
      DATABASE_USER=${POSTGRES_USER}
      DATABASE_PASSWORD=${POSTGRES_PASSWORD}
      DATABASE_NAME=${POSTGRES_DB}
      REDIS_HOST=redis
      REDIS_PASSWORD=${REDIS_PASSWORD}

Important point:
There is no reference to the hostname “database” anywhere in the new compose file.

What I have already tried:

  • Removed all containers (docker rm -f …)
  • Removed all images (docker rmi …)
  • Recreated the .env file
  • Recreated docker-compose.yml from scratch
  • Deleted old folders
  • Ran docker compose up --force-recreate
  • Fresh WSL installation
  • Fresh Docker Desktop installation
  • Confirmed correct docker context
  • Verified that “postgres” resolves correctly on the internal network

But Immich server logs still show:
hostname: ‘database’

Expected behavior:
Immich server should connect to Postgres using:
DATABASE_HOST=postgres

Actual behavior:
Immich server ignores DATABASE_HOST and falls back to “database”, causing DNS failure and crashing repeatedly.

Question:
Why does Immich server continue trying to resolve “database” even after:

  • full reset
  • new compose
  • new env
  • deleted images
  • deleted containers

Is this:

  • an internal default inside the image?
  • a Docker Desktop environment caching issue?
  • WSL2 environment override?
  • leftover metadata or labels?
  • something else entirely?

Looking for guidance on how to completely remove any old configuration and ensure Immich uses the correct DATABASE_HOST value.
Thanks.

Maybe take a look at James config files.

It looks like you suspected everything, except immich configuration issue. After checking the documentation, I found an example compose file which contains a service called “database”.

https://docs.immich.app/install/docker-compose

There is also an env file, but the daabase host is not set, so “database” must be the default. The used variables start with “DB_” and not “DATABASE_”.

After clicking “environment variables” in the navigation of the documentation, I see that the database host name can be set in DB_HOSTNAME and not DATABASE_HOSTNAME.

https://docs.immich.app/install/environment-variables

Quote:

Variable Description Default Containers
DB_URL Database URL server
DB_HOSTNAME Database host database server
DB_PORT Database port 5432 server
DB_USERNAME Database user postgres server, database*1
DB_PASSWORD Database password postgres server, database*1
DB_DATABASE_NAME Database name immich server, database*1