Development container is a full-featured coding environment. Rails 7.2 introduces configurations for these containers in your application, including a .devcontainer
folder with Dockerfile
, docker-compose.yml
, and devcontainer.json
.
The default dev container includes:
- A database (SQLite, Postgres, MySQL, or MariaDB)
- Active Storage with local disk usage and preview features
- A Redis container
- A Headless Chrome container for system tests
Generate a new application with a development container using:
rails new myapp --devcontainer
After this, you will see the result of the generator:
...
create storage/.keep
create tmp/storage
create tmp/storage/.keep
create .devcontainer
create .devcontainer/devcontainer.json
create .devcontainer/Dockerfile
create .devcontainer/compose.yaml
...
As you can see, the generator created files that correspond to the container configuration.
For existing applications, use:
rails devcontainer
Result:
╰─ $ rails devcontainer
Generating Dev Container with the following options:
app_name: rails_blog
database: sqlite3
active_storage: true
redis: true
system_test: true
node: false
create .devcontainer
create .devcontainer/devcontainer.json
create .devcontainer/Dockerfile
create .devcontainer/compose.yaml
gsub test/application_system_test_case.rb
More details in the Getting Started with Dev Containers guide.
We have previously written about how to set up Docker for Ruby on Rails 7. In this article you can find more detailed information on how to configure docker:
Setting Up Docker for Ruby on Rails 7
Top comments (2)
Thank you for your post.
I am using Mac M1 and follow this guide guides.rubyonrails.org/getting_sta... to setup Rails env with DevContainer
I run
rails-new blog --devcontainer
The result with no any configuration file related devcontainer created.
Please help to address the issue.
Thanks
Hi tqv thu, to understand what is the reason we need more information about the problem. Logs, all steps to reproduce, etc.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.