Skip to content

📝 .env Files

.env files are used to store variables and secrets. There are used whenver possible.

Note

Because they can hold secrets, they are ignored by git.

Template

Since the file is ignored by git, the template file may be copied, if it exists.

.env.tmpl

cp .env.tmpl .env

🔑 Secrets

If secrets are kept in the .env file, the file is encrypted using SOPS and stored as .env.enc.

Warning

Storing encrypted secrets in a public repo is risky and is not recommended!

🤝 Service

appname.service

[Service]
EnvironmentFile=/root/git/nicholaswilde/homelab/pve/appname/.env

Task

Taskfile.yml

dotenv:
  - .env

Docker Compose

compose.yaml

services:
  appname:
    env_file:
      - .env

📜 Shell Script

script.sh

DEFAULT_VALUE=foo
source .env

🔗 References