2021-09-26 15:07:00 -07:00

2022-09-06 08:09:27 -07:00
Start here: https://github.com/ryanwi/rails7-on-docker/generate
2021-09-26 15:09:56 -07:00
# Rails 7 on Docker demo application
2021-09-26 15:07:00 -07:00
This app demonstrates Rails 7 with PostgreSQL, import maps, turbo, stimulus and hotwire, all running in Docker.
2021-09-28 15:59:44 -07:00
**NOTE: ** [There is also an example Rails 6 application working in Docker with Webpacker ](https://github.com/ryanwi/rails-on-docker )
2021-09-30 21:04:49 -07:00
## Features
2022-01-17 10:11:32 -08:00
* Rails 7
* Ruby 3
2021-09-30 21:04:49 -07:00
* Dockerfile and Docker Compose configuration
* PostgreSQL database
* Redis
2021-09-30 21:07:57 -07:00
* GitHub Actions for
* tests
* Rubocop for linting
2022-01-17 10:11:32 -08:00
* Security checks with [Brakeman ](https://github.com/presidentbeef/brakeman ) and [bundler-audit ](https://github.com/rubysec/bundler-audit )
2021-09-30 21:06:25 -07:00
* Dependabot for automated updates
2021-09-28 15:59:44 -07:00
2022-09-17 16:40:11 -07:00
## Requirements
2022-09-19 09:15:39 -07:00
Please ensure you are using Docker Compose V2. This project relies on the `docker compose` command, not the previous `docker-compose` standalone program.
2022-09-17 16:40:11 -07:00
https://docs.docker.com/compose/#compose -v2-and-the-new-docker-compose-command
Check your docker compose version with:
```
% docker compose version
Docker Compose version v2.10.2
```
2021-09-26 15:07:00 -07:00
## Initial setup
```
2021-11-13 17:23:06 -08:00
cp .env.example .env
2021-09-26 15:07:00 -07:00
docker compose build
docker compose run --rm web bin/rails db:setup
```
## Running the Rails app
```
docker compose up
```
## Running the Rails console
When the app is already running with `docker-compose` up, attach to the container:
```
docker compose exec web bin/rails c
```
When no container running yet, start up a new one:
```
docker compose run --rm web bin/rails c
```
## Running tests
```
2022-03-15 21:03:01 -07:00
docker compose run --rm web bin/rspec
2021-09-26 15:07:00 -07:00
```
## Updating gems
```
docker compose run --rm web bundle update
docker compose up --build
```
2022-04-24 22:52:31 -07:00
## Production build
```
docker build -f production.Dockerfile .
```
2021-09-26 15:07:00 -07:00
2022-09-10 15:35:00 -07:00
## Deployment
This app can be hosted wherever Ruby is supported and PostgreSQL databases can be provisioned.
#### Render
[](https://render.com/deploy?repo=https://github.com/ryanwi/rails7-on-docker)
2022-09-10 17:53:39 -07:00
NOTE: You will need to generate a production secret with `bin/rails secret` and set it as the `SECRET_KEY_BASE` environment variable.
2022-09-10 15:35:00 -07:00
2021-09-26 15:07:00 -07:00
## Credits/References
### Rails with Docker
2021-09-30 21:19:06 -07:00
* [Quickstart: Compose and Rails ](https://docs.docker.com/compose/rails/ )
* [Docker for Rails Developers
2022-03-30 15:31:55 -07:00
Build, Ship, and Run Your Applications Everywhere](https://pragprog.com/titles/ridocker/docker-for-rails-developers/)
2021-09-30 21:19:06 -07:00
* [Ruby on Whales:
Dockerizing Ruby and Rails development](https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development)
2021-09-26 15:07:00 -07:00
2021-09-30 21:02:31 -07:00
### Rails 7 with importmaps
* [Alpha preview: Modern JavaScript in Rails 7 without Webpack ](https://www.youtube.com/watch?v=PtxZvFnL2i0 )
### Rails 7 with hotwire
* [Stimulus 3 + Turbo 7 = Hotwire 1.0 ](https://world.hey.com/dhh/stimulus-3-turbo-7-hotwire-1-0-9d507133 )
* [Turbo 7 ](https://world.hey.com/hotwired/turbo-7-0dd7a27f )
* [Rails 7 will have three great answers to JavaScript in 2021+ ](https://world.hey.com/dhh/rails-7-will-have-three-great-answers-to-javascript-in-2021-8d68191b )
* [Hotwire Turbo Replacing Rails UJS ](https://www.driftingruby.com/episodes/hotwire-turbo-replacing-rails-ujs )
2022-09-10 18:07:24 -07:00
## Author
**Ryan Williams **
- <https://www.ryanwilliams.dev>
- <https://twitter.com/ryanwi>
2023-01-22 16:33:43 -08:00
- <https://hachyderm.io/@ryanwi >
2022-09-10 18:07:24 -07:00
- <https://github.com/ryanwi>