{"record":{"id":"ef99addcc0bd1e46","repo":"docker/compose","slug":"env-file-s-not-found","errorCode":null,"errorMessage":"env file %s not found","messagePattern":"env file (.+?) not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compose/publish.go","lineNumber":711,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tfindings, err := scan.ScanReader(in)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to scan compose file %s: %w\", file, err)\n\t\t}\n\t\tallFindings = append(allFindings, findings...)\n\t}\n\tfor _, service := range project.Services {\n\t\t// Check env files\n\t\tfor _, envFile := range service.EnvFiles {\n\t\t\tif _, statErr := os.Stat(envFile.Path); statErr != nil {\n\t\t\t\tif !os.IsNotExist(statErr) {\n\t\t\t\t\treturn nil, fmt.Errorf(\"failed to access env file %s: %w\", envFile.Path, statErr)\n\t\t\t\t}\n\t\t\t\tif envFile.Required {\n\t\t\t\t\treturn nil, fmt.Errorf(\"env file %s not found\", envFile.Path)\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfindings, err := scan.ScanFile(envFile.Path)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to scan env file %s: %w\", envFile.Path, err)\n\t\t\t}\n\t\t\tallFindings = append(allFindings, findings...)\n\t\t}\n\t}\n\n\t// Check configs defined by files\n\tfor _, config := range project.Configs {\n\t\tif config.File != \"\" {\n\t\t\tfindings, err := scan.ScanFile(config.File)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to scan config file %s: %w\", config.File, err)\n\t\t\t}","sourceCodeStart":693,"sourceCodeEnd":729,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/compose/publish.go#L693-L729","documentation":"The pre-publish secret scan found a service env_file that does not exist on disk and is marked required (required: true, or defaulted as required by the loader). Required env files must be present so their contents can be scanned; a missing one aborts the publish.","triggerScenarios":"Publishing a project where a service declares env_file: ./prod.env (or an entry with required: true) and the file is absent at scan time. Optional files (required: false) are skipped silently instead.","commonSituations":"Env files excluded by .gitignore so teammates/CI lack them; deploying from a fresh checkout without copying the env template; path typos; the file living outside the build context in CI.","solutions":["Create the missing file at the exact path shown in the error, or copy it from your template (cp .env.example .env).","If the file is intentionally optional, declare it with required: false in the compose file.","Fix the path if it is a typo or resolved against the wrong working directory (relative paths resolve from the compose file's directory).","In CI, ensure the env file step (secret injection) runs before docker compose publish."],"exampleFix":"# before\nservices:\n  api:\n    env_file:\n      - ./.env.prod    # missing, required by default\n\n# after (optional file)\nservices:\n  api:\n    env_file:\n      - path: ./.env.prod\n        required: false","handlingStrategy":"validation","validationCode":"func requireEnvFiles(project *types.Project) error {\n\tfor _, svc := range project.Services {\n\t\tfor _, ef := range svc.EnvFiles {\n\t\t\tif !ef.Required {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif _, err := os.Stat(ef.Path); errors.Is(err, fs.ErrNotExist) {\n\t\t\t\treturn fmt.Errorf(\"required env file %s missing\", ef.Path)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if err := publish(ctx, opts); err != nil {\n    if strings.Contains(err.Error(), \"env file\") && strings.Contains(err.Error(), \"not found\") {\n        // create the file from template or mark required: false, retry\n    }\n    return err\n}","preventionTips":["Commit .env templates and add a CI check that required env files exist.","Mark truly optional env files with required: false.","Resolve relative env_file paths against the compose file's directory to avoid working-dir drift."],"tags":["compose","publish","env-file","missing-file"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}