Source: Ruby on Whales: Dockerizing Ruby and Rails development.
- Docker installed.
For MacOS just use the official app.
dip
installed.
You can install dip
as Ruby gem:
gem install dip
-
Build image:
dip build
-
Install yarn packages:
dip yarn install --ignore-engines
-
Install gems:
dip bundle install
-
Create databases:
dip rails db:create
and thendip rails db:create RAILS_ENV=test
-
Enable postgis extensions
dip psql
When prompted for a password, enter:postgres
Once inside the psql console, runCREATE EXTENSION postgis;
exit
-
Run
dip rake db:gis:setup
-
Run migrations:
dip rails db:migrate
-
Seed db:
dip rails db:seed
-
Finally, start the container with
dip up
-
Wait until everything is up and then open a browser in port 3000
# run rails console
dip rails c
# run rails server with debugging capabilities (i.e., `debugger` would work)
dip rails s
# or run the while web app (with all the dependencies)
dip up web
# run migrations
dip rails db:migrate
# pass env variables into application
dip VERSION=20100905201547 rails db:migrate:down
# simply launch bash within app directory (with dependencies up)
dip runner
# execute an arbitrary command via Bash
dip bash -c 'ls -al tmp/cache'
# Additional commands
# update gems or packages
dip bundle install
dip yarn install --ignore-engines
# run psql console
dip psql
# run Redis console
dip redis-cli
# run tests
# TIP: `dip rspec` is already auto prefixed with `RAILS_ENV=test`
dip rspec spec/path/to/single/test.rb:23
# shutdown all containers
dip down
Another way is to run dip <smth>
for every interaction. If you prefer this way and use ZSH, you can reduce the typing
by integrating dip
into your session:
$ dip console | source /dev/stdin
# no `dip` prefix is required anymore!
$ rails c
Loading development environment (Rails 7.0.1)
pry>