Skip to content

Instantly share code, notes, and snippets.

@kaosf
Last active September 9, 2022 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaosf/f4451b36e55012e6b7d1781e6a88df6a to your computer and use it in GitHub Desktop.
Save kaosf/f4451b36e55012e6b7d1781e6a88df6a to your computer and use it in GitHub Desktop.
Active Record in Docker
$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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment