dify-plugin-daemon container crashes on startup due to missing .env file #243

Open
opened 2026-02-16 01:15:05 -05:00 by yindo · 1 comment
Owner

Originally created by @weichun-wang on GitHub (Jan 28, 2026).

Self Checks

To make sure we get to you in time, please check the following :)

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • "Please do not modify this template :) and fill in all the required fields."

Versions

  1. dify-plugin-daemon main-local
  2. dify-api main

Describe the bug
When starting Dify locally using docker compose up -d, the plugin_daemon container fails to start with an error indicating it cannot find the .env file.

The error message shows:

goroutine 1 [running]:
github.com/langgenius/dify-plugin-daemon/pkg/utils/log.Panic(...)
 /app/pkg/utils/log/log.go:70
main.main()
 /app/cmd/server/main.go:19 +0x3e5
2026/01/29 02:11:45 ERROR failed to load .env file error="open .env: no such file or directory"
panic: failed to load .env file

To Reproduce
Steps to reproduce the behavior:
1. Clone Dify repository and navigate to the docker deployment directory
2. Run docker compose up -d
3. Check the logs for the plugin_daemon container using docker logs dify-plugin_daemon-1
4. See the error about missing .env file

Expected behavior
We have already set the environment variables in docker-compose.yml (screenshot below). The container should contain a .env template file with placeholders, and the container should automatically read environment variables during startup. Alternatively, the container should be able to start without requiring a physical .env file in its working directory.

Screenshots

Image

Additional context
Issue Analysis:
The dify-plugin-daemon application requires a .env file at startup, but the official Docker image doesn't include it. While the source repository contains a .env.example template file, it's not copied into the Docker image during the build process.

Root Cause:
The Go application (line 19 in main.go) calls godotenv.Load() which expects a .env file in the working directory. However, the Dockerfile doesn't copy .env.example or create a .env file, causing the container to fail on startup.

Evidence:
1. Source repository has .env.example but not .env
2. Docker image inspection shows neither file exists in /app/
3. Error trace points to main.go:19 where godotenv.Load() is called

Originally created by @weichun-wang on GitHub (Jan 28, 2026). **Self Checks** To make sure we get to you in time, please check the following :) - [ ] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify-plugin-daemon/issues), including closed ones. - [ ] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [ ] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [ ] "Please do not modify this template :) and fill in all the required fields." **Versions** 1. dify-plugin-daemon main-local 2. dify-api main **Describe the bug** When starting Dify locally using docker compose up -d, the plugin_daemon container fails to start with an error indicating it cannot find the .env file. The error message shows: ```text goroutine 1 [running]: github.com/langgenius/dify-plugin-daemon/pkg/utils/log.Panic(...) /app/pkg/utils/log/log.go:70 main.main() /app/cmd/server/main.go:19 +0x3e5 2026/01/29 02:11:45 ERROR failed to load .env file error="open .env: no such file or directory" panic: failed to load .env file ``` **To Reproduce** Steps to reproduce the behavior: 1. Clone Dify repository and navigate to the docker deployment directory 2. Run docker compose up -d 3. Check the logs for the plugin_daemon container using docker logs dify-plugin_daemon-1 4. See the error about missing .env file **Expected behavior** We have already set the environment variables in docker-compose.yml (screenshot below). The container should contain a .env template file with placeholders, and the container should automatically read environment variables during startup. Alternatively, the container should be able to start without requiring a physical .env file in its working directory. **Screenshots** <img width="318" height="1120" alt="Image" src="https://github.com/user-attachments/assets/714e6db7-0671-4373-94aa-6f6503e62538" /> **Additional context** ***Issue Analysis:*** The dify-plugin-daemon application requires a .env file at startup, but the official Docker image doesn't include it. While the source repository contains a .env.example template file, it's not copied into the Docker image during the build process. ***Root Cause:*** The Go application (line 19 in main.go) calls godotenv.Load() which expects a .env file in the working directory. However, the Dockerfile doesn't copy .env.example or create a .env file, causing the container to fail on startup. ***Evidence:*** 1. Source repository has .env.example but not .env 2. Docker image inspection shows neither file exists in /app/ 3. Error trace points to main.go:19 where godotenv.Load() is called
yindo added the plugin-daemonbug labels 2026-02-16 01:15:05 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 28, 2026):

Hi @weichun-wang! I'm Dosu and I’m helping the dify-plugin-daemon team.

The container crash happens because the application calls godotenv.Load() unconditionally at startup and panics if the .env file is missing, even if all required environment variables are set in docker-compose.yml. The Docker image does not include a .env file by default, so the container fails to start unless you provide one. This is a known issue and has been discussed in several threads, with maintainers suggesting workarounds like manually adding the required environment variables or ensuring a .env file is present in the container [source].

To work around this, you can: (1) copy .env.example to .env and mount it into the container using a Docker volume, (2) modify your Dockerfile or compose setup to generate a .env file at build or startup, or (3) patch main.go to only load the .env file if it exists, so the app can rely on environment variables set by Docker. Until the application is updated to handle missing .env files gracefully, the most robust solution is to ensure a .env file is present in the container at startup [source].

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Jan 28, 2026): <!-- Greeting --> Hi @weichun-wang! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify-plugin-daemon team. <!-- Answer --> The container crash happens because the application calls godotenv.Load() unconditionally at startup and panics if the .env file is missing, even if all required environment variables are set in docker-compose.yml. The Docker image does not include a .env file by default, so the container fails to start unless you provide one. This is a known issue and has been discussed in several threads, with maintainers suggesting workarounds like manually adding the required environment variables or ensuring a .env file is present in the container [[source]](https://github.com/langgenius/dify-plugin-daemon/issues/350). To work around this, you can: (1) copy .env.example to .env and mount it into the container using a Docker volume, (2) modify your Dockerfile or compose setup to generate a .env file at build or startup, or (3) patch main.go to only load the .env file if it exists, so the app can rely on environment variables set by Docker. Until the application is updated to handle missing .env files gracefully, the most robust solution is to ensure a .env file is present in the container at startup [[source]](https://github.com/langgenius/dify-plugin-daemon/blob/f272e6c3fcd8a18c6ff571d7fcbfde857f63ef99/cmd/server/main.go#L13-L34). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/8a8b422d-4aad-4061-8898-d00dd91e333c?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/8a8b422d-4aad-4061-8898-d00dd91e333c?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/8a8b422d-4aad-4061-8898-d00dd91e333c?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/8a8b422d-4aad-4061-8898-d00dd91e333c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/8a8b422d-4aad-4061-8898-d00dd91e333c?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/8a8b422d-4aad-4061-8898-d00dd91e333c?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/8a8b422d-4aad-4061-8898-d00dd91e333c?feedback_type=other)</sup> [![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20container%20crash%20happens%20because%20the%20application%20calls%20godotenv.Load%28%29%20unconditionally%20at%20startup%20and%20panics%20if%20the%20.env%20file%20is%20missing%2C%20even%20if%20all%20required%20environment%20variables%20are%20set%20in%20docker-compose.yml.%20The%20Docker%20image%20does%20not%20include%20a%20.env%20file%20by%20default%2C%20so%20the%20container%20fails%20to%20start%20unless%20you%20provide%20one.%20This%20is%20a%20known%20issue%20and%20has%20been%20discussed%20in%20several%20threads%2C%20with%20maintainers%20suggesting%20workarounds%20like%20manually%20adding%20the%20required%20environment%20variables%20or%20ensuring%20a%20.env%20file%20is%20present%20in%20the%20container%20%5B%5Bsource%5D%5D%28https%3A//github.com/langgenius/dify-plugin-daemon/issues/350%29.%0A%0ATo%20work%20around%20this%2C%20you%20can%3A%20%281%29%20copy%20.env.example%20to%20.env%20and%20mount%20it%20into%20the%20container%20using%20a%20Docker%20volume%2C%20%282%29%20modify%20your%20Dockerfile%20or%20compose%20setup%20to%20generate%20a%20.env%20file%20at%20build%20or%20startup%2C%20or%20%283%29%20patch%20main.go%20to%20only%20load%20the%20.env%20file%20if%20it%20exists%2C%20so%20the%20app%20can%20rely%20on%20environment%20variables%20set%20by%20Docker.%20Until%20the%20application%20is%20updated%20to%20handle%20missing%20.env%20files%20gracefully%2C%20the%20most%20robust%20solution%20is%20to%20ensure%20a%20.env%20file%20is%20present%20in%20the%20container%20at%20startup%20%5B%5Bsource%5D%5D%28https%3A//github.com/langgenius/dify-plugin-daemon/blob/f272e6c3fcd8a18c6ff571d7fcbfde857f63ef99/cmd/server/main.go%23L13-L34%29.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify-plugin-daemon/issues/592)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-plugin-daemon#243