To enable stdout flush.
ref. https://hawksnowlog.blogspot.com/2019/04/dose-not-show-puts-output-on-docker.html
Parse DATABASE_URL URI for establish_connection.
| $stdout = IO.new(IO.sysopen("/proc/1/fd/1", "w"), "w") | |
| $stdout.sync = true | |
| require "active_record" | |
| I18n.enforce_available_locales = false | |
| require "uri" | |
| ActiveRecord::Base.establish_connection ENV["DATABASE_URL"] | |
| # Write your code | |
| class YourModel < ActiveRecord::Base; end | |
| puts YourModel.count |
| FROM ruby | |
| COPY ["Gemfile", "Gemfile.lock", "app.rb", "/"] | |
| RUN bundle | |
| CMD ["ruby", "/app.rb"] |
| source "https://rubygems.org" | |
| gem "activerecord" | |
| gem "pg" |
To enable stdout flush.
ref. https://hawksnowlog.blogspot.com/2019/04/dose-not-show-puts-output-on-docker.html
Parse DATABASE_URL URI for establish_connection.
| # to generate Gemfile.lock | |
| bundle | |
| docker image build . -t your-image-name | |
| docker container run --rm -e DATABASE_URL=postgres://username:password@host:5432/databasename your-image-name |