joho / godotenv

A Go port of Ruby's dotenv library (Loads environment variables from .env files)
http://godoc.org/github.com/joho/godotenv
MIT License
8.45k stars 405 forks source link

open ../.env: no such file or directory (Docker Image build) #236

Open Ndeta100 opened 2 months ago

Ndeta100 commented 2 months ago

I get this error when I build and publish my docker image then I try to pull and run it locally or on a vm with coolify. I have added my env as github secrets for the builf process but I still get the same error, even after adding the env variables to coolify. It suggested I neeet to comment out godotenv.Load(), but still same issue. Anyone can help?

func init() { if err := godotenv.Load(); err != nil { log.Fatal(err) } }

abuzaforfagun commented 1 month ago

Probably you have placed the .env file in the wrong directory. For an example, here is my file and folder structure:

│   .env
│   .env.test
│   go.mod
│   go.sum
│   readme.md
│   
├───cmd
│   ├───api
│   │       main.go

I have used the godotenv.Load(file_path) in the main.go file. Here is my code: godotenv.Load("../../.env")