With reference to Docker official procedure, we will explain in detail the procedure for building a Docker development environment on Rails 6 series.
A detailed explanation of each command is explained in Procedures in Rails 5 series that I wrote earlier, so I will omit it in this article.
$ docker-compose run web rails new . --force --no-deps --database=mysql
$ docker-compose build
After executing the above, modify the config / database.yml file completely as follows.
config/database.yml
default: &default
adapter: mysql2
encoding: utf8mb4
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password:
host: localhost
development:
<<: *default
database: myapp_development
host: db
username: root
password: password
test:
<<: *default
database: myapp_test
host: db
username: root
password: password
$ docker-compose run web rails db:create
Since Webpacker is required from Rails 6 series, install webpacker in the container of the web server.
$ docker-compose run web rails webpacker:install
$ docker-compose up -d
Access ** localhost: 3000 ** from your browser and check that the Rails initial screen is displayed.
Use docker-compose to stop the container after validation.
$ docker-compose down
Recommended Posts