env file ...\web.env not found: GetFileAttributesEx ...: The system cannot find the file specified. means a service's env_file: entry points at a file that does not exist, so Compose stops before starting anything. Create the file, fix the path, or mark the entry required: false if the file is optional.

The path in the message is the full path Compose looked at. Compare it with where the file really is; a wrong folder or a wrong name gives the same message.

The error

PS> docker compose up
env file C:\...\e4\web.env not found: GetFileAttributesEx C:\...\e4\web.env: The system cannot find the file specified.

The file (the long folder path is shortened to C:\...\e4, nothing else changed):

name: fix8-cli-e4
services:
  web:
    image: alpine
    command: ["sh", "-c", "echo db=$$DB_HOST"]
    env_file:
      - web.env

Why it happens

env_file tells Compose to read variables from a file and pass them into the container. In the short form above, every listed file must exist. The folder in the test held only the two Compose files, so Compose stopped at once. The second half of the message, GetFileAttributesEx, is the Windows call that failed; it adds nothing beyond "not found".

A fresh clone is a likely place to meet it: a file that holds secrets is often kept out of Git, so it does not arrive with the repository and has to be created by hand.

The fix

Create the file:

PS> docker compose up
web-1  | db=db.example.test

Or, if the stack should start without it, use the long form with required: false, which this Compose accepted:

    env_file:
      - path: web.env
        required: false
PS> docker compose -f compose.optional.yaml up
web-1  | db=

With web.env holding DB_HOST=db.example.test the container printed the value; with the optional form and no file it started and printed an empty value. The up outputs are trimmed to the container's line. Prefer creating the file: an optional entry hides the mistake and moves the failure into the application.

How it was reproduced

Docker Desktop on Windows 11, engine 29.9.2, Docker Compose v5.6.1, Windows PowerShell 5.1, the cached alpine:latest image. A one-service Compose file with env_file: - web.env and no such file gave the message above; the required: false form started, and creating the file fixed the original. The project name fix8-cli-e4 is the test's own.

Frequently asked

Where does docker compose look for an env_file?
In this test it looked next to compose.yaml: the entry web.env was printed as ...\e4\web.env, the Compose file's folder. Compare that full path with where the file really is, then fix the entry or move the file.
How do I make an env_file optional in docker compose?
Use the long form: a list entry with path: <file> and required: false. Compose v5.6.1 then starts without the file.
What is the difference between env_file and .env in docker compose?
env_file passes variables into the container. The .env file next to the Compose file fills ${NAME} placeholders in the Compose file itself.

More decoded errors in the Fixes category. For variables used inside the Compose file itself, see variable is not set.