Hello. This time, I summarized the procedure to introduce Docker to the development environment of the existing Rails application. I haven't studied enough yet, so I would appreciate it if you could point out any corrections or improvements.
-Install Docker-for-mac --Existing Rails app (This time I will use the simple household account book app I created earlier.)
Ruby:2.5.3 Rails:5.2.4.3 MySQL:5.6 Docker:19.03.8 docker-compose:1.25.4
Create Dockerfile
and docker-compose.yml
directly under the root directory of your existing Rails app.
Below are the contents of each file.
Dockerfile
FROM ruby:2.5.3
RUN apt-get update && apt-get install -y \
build-essential \
nodejs
WORKDIR /kakeibo
COPY Gemfile Gemfile.lock /kakeibo/
RUN bundle install
--For the FROM ruby: 2.5.3
part, match it with the Ruby version of the app.
--RUN apt-get update && apt-get install -y ~
to install the required packages.
--Create a folder in the container with WORKDIR / kakeibo
.
--Copy Gemfile and Gemfile.lock into the container with COPY Gemfile Gemfile.lock / kakeibo /
, then run bundle install
.
docker-compose.yml
version: '3'
volumes:
mysql-data:
services:
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
ports:
- '3000:3000'
volumes:
- '.:/kakeibo'
tty: true
stdin_open: true
depends_on:
- db
links:
- db
db:
image: mysql:5.6
volumes:
- 'mysql-data:/var/lib/mysql'
environment:
- 'MYSQL_ROOT_PASSWORD=password'
A detailed explanation of the contents of Dockerfile
and docker-compose.yml
is summarized in this article.
default: &default
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password: password
host: db
development:
<<: *default
database: kakeibo_development
Match the password
and host
in config / database.yml
to the values set in docker-compose.yml.
$ docker-compose build
$ docker-compose up -d
$ docker-compose exec web rails db:create
$ docker-compose exec web rails db:migrate
Now when you visit http: // localhost: 3000, you should be able to see the app successfully.
-Procedure for developing an existing rails project with Docker -Procedure to install Docker in existing Rails app -Create an existing application development environment with Docker [Ruby2.6 + Rails5.2 + Mysql5.7] -[Rails] Procedure for creating Rails + MySQL development environment with Docker -Docker beginners carefully summarize the procedure for building a virtual environment with Rails + PostgreSQL or MySQL -#Linux #Ubuntu #docker #Dockerfile What is this? apt-get install --no-install-recommends -"Dockerfile Best Practices"
Recommended Posts