Be Your Own Cloud code · PART 2 — FOUNDATION

Chapter 9 Secrets and Environment Files: Doing This Safely From Day One

4 blocks · pp. 42–43 in the paperback

The .env Pattern

# p. 42

File .env — beside each service's docker-compose.yml
# .env
ADMIN_TOKEN=changeme_to_a_long_random_string
DB_PASSWORD=changeme_to_a_long_random_string

# p. 42

Add to docker-compose.yml

How a compose file reads a value from .env.

# docker-compose.yml references it like this:
environment:
  - ADMIN_TOKEN=${ADMIN_TOKEN}

Locking the File Down

# p. 42

Run Terminal, inside each service's folder
chmod 600 .env
echo '.env' >> .gitignore

The Bootstrap Problem

# p. 43

Run Terminal, on the server
# generates a strong random value for any secret you need now
openssl rand -base64 48

Reproduced exactly from Be Your Own Cloud, Chapter 9. The book explains what each line does and what to do when it doesn't work. About the book

Something here not working as the book describes? Tell the author.