Skip to content

Add section in README describing workaround when using dotenv_validator with Docker #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@ MY_WEIRD_ENV_VAR=123_ABC #required,format=\d{3}_\w{3}

In the above example, `\d{3}_\w{3}` is converted to a regexp and the value is checked against it.

## If you use `docker-compose`, read this

Docker Compose automatically reads `.env` files present in the project's root when running `docker-compose up`. What this means is that, if you use `dotenv_validator` in an app you run using Docker Compose, you might get exceptions or warnings about your variables being in the wrong format even though they're right. The reason is that, when running `docker-compose up`, docker-compose parses the `.env` file before the Rails application starts. It reads each line as is with a really simple parser (no quotes, comments and trailing spaces handling).

Then, since `docker-compose` already set the environment variables, the Dotenv gem won't override them. It parses the file as we'd expect, but it won't change env variables that are already set.

For more information check this [page](https://docs.docker.com/compose/environment-variables/#set-environment-variables-in-containers) from their docs.

The workaround is to rename your `.env` file when using docker. [Here](https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use) you'll find all naming options acceptable for dotenv and that Docker will not automatically parse.

If renaming is not an option, then you need to remove any comments or trailing whitespaces from your `.env` file:
```
SMTP_PORT=25 #format=int
```
needs to become:
```
SMTP_PORT=25
```

### TL;DR
Rename your `.env` file according to this [table](https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use)

or

Remove all comments and trailing whitespaces

## Contributing

Want to make your first contribution to this project? Get started with some of [our good first issues](https://github.com/fastruby/dotenv_validator/contribute)!
Expand All @@ -81,4 +107,4 @@ When Submitting a Pull Request:

![FastRuby.io | Rails Upgrade Services](fastruby-logo.png)

`dotenv_validator` is maintained and funded by [FastRuby.io](https://fastruby.io). The names and logos for FastRuby.io are trademarks of The Lean Software Boutique LLC.
`dotenv_validator` is maintained and funded by [FastRuby.io](https://fastruby.io). The names and logos for FastRuby.io are trademarks of The Lean Software Boutique LLC.