How to manage API keys and passwords that should not be published in Rails development using Docker in a separate file.
Gemfile
gem 'dotenv-rails'
bash
docker-compose run container name bundle install
By writing env_file in yml, you can set to read the file that manages environment variables.
docker-compose.yml
code:docker-compose.yml
web:
abridgement
env-file:
- .env(Describe the file name for which you want to manage environment variables)
I edited docker-compose.yml, so I will build it again.
docker-compose build
.env
MAP_API_KEY="Issued API key"
PASSWORD="password"
.gitignore
/.env
ruby:index.html.erb
Omitted above
<script src="https://maps.googleapis.com/maps/api/js?key=<%=ENV['MAP_API_KEY']%>&callback=initMap" async defer></script>
The important thing here is to write <% = ENV ['']%>
according to the erb template.
Without doing this, I wrote ENV ['MAP_API_KEY']
and handed it over, and I couldn't display it in view well, and it was stuck for about 2 days.
Recommended Posts