-
Notifications
You must be signed in to change notification settings - Fork 413
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
Rails config/database.yml
is read from Docker env vars but mysql2 defaults to root
and ignores host
and other opts
#211
Comments
Also, rails console using docker exec works just fine, its just the server that fails trying to connect to the mysql database even though the ENV seems to have the environment variables passed in as docker env vars. |
Facing the same thing (no connection from browser when using env vars in database.yml) I just came across : https://github.com/phusion/passenger-docker#nginx_env_vars Seems nginx clears all ENV vars from child processes. So they are preserved when running a local bash/rails console but are missing when going via passenger |
I've been trying to find a way around this problem too. I think you want to use The combination that seems to work (and feels super hacky to me) is to make a template nginx config file and then use If someone can come up with a better way to do this, I would be very interested. |
Hello, This is a tad old, but still a problem to this day. just adding information that Rails in config/database.yml expects a host entry for each environment. if a host entry is blank or with a <%= ENV['DB_HOSTNAME'] %> it actually defaults to development regardless. You can test this by removing all environment entries and leaving e.g. staging only, then running it with the following config: staging: This is at least the case for postgres, with pg gem ~> 1.2.3 and will yield a message stating: ActiveRecord::AdapterNotSpecified: 'development' database is not configured. Available: ["staging"] just wanted to add this in case someone was hitting the same issue. I've been troubleshooting an ENV error on aws + docker + rails which was a direct result of this. Took me 8 hours to properly troubleshoot as i was starting in the AWS pipeline then proceeded to docker and eventually discovered it was Rails. |
I'm running into an issue with the following passenger-docker setup (see below), the rails
config/application.rb
file does pick up the right env vars passed to thedocker run
command. However, in the stack trace, mysql2 still tries to connect usingroot
and local socket, ignoring the host, username and password env vars that are passed inDockerfile
nginx.conf
rails-env.conf
The docker command is
docker run -d -e PASSENGER_APP_ENV=development -e DB=appname_development -e DB_USER=user -e DB_PASS=pass -e DB_HOST=10.0.2.2 -p 80:80
The text was updated successfully, but these errors were encountered: