1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【mac】 docker + rails + mysql で環境構築

Posted at

【mac】 docker + rails + mysql で環境構築

【rails環境構築】docker + rails + mysql で環境構築(初心者でも30分で完了!)https://www.youtube.com/watch?v=Fq1PH0Gwi8I
の動画を見て環境構築の必要コードとエラー対処をまとめてみました。

作業フォルダを作成移動

mkdir sample_app
cd sample_app

ファイルを作成 中身はテキストエディタを開いてコピペ

touch Dockerfile
touch Gemfile 
touch Gemfile.lock 
touch docker-compose.yml 

imageの構築とコンテナの構築・起動

docker-compose run web rails new . --force --database=mysql --skip-bundle
docker-compose build

config/database.ymlのpasswordをpasswordにとhostをdbに変更

BC59CC20-55C5-4F23-B71A-43A0244321CB_1_201_a.jpeg

上の変更を反映させる

docker-compose build
docker-compose up

画面を開く

Could not find gem ‘mysql2 (>= 0.4.4, < 0.6.0)’ in any of the gem sources listed in your Gemfile.への対処

docker-compose run web bundle install
docker-compose up

Unknown MySQL server host 'db' (-2)への対処

名前を適当に変更MYSQL_USER: app_ppに変更
067DB6F7-5053-42E0-8867-12520632C136_1_201_a.jpeg

dbの作成

docker-compose run web rails db:create
docker-compose run web rails db:migrate

完成

Yay! You’re on Rails!が画面に表示されれば完成です。

今回ターミナルに打ったコードまとめ

mkdir sample_app
cd sample_app
touch Dockerfile
touch Gemfile 
touch Gemfile.lock
touch docker-compose.yml
docker-compose run web rails new . --force --database=mysql --skip-bundle
docker-compose build
docker-compose up
docker-compose run web bundle install
docker-compose up
docker-compose run web rails db:create
docker-compose run web rails db:migrate

参考

【rails環境構築】docker + rails + mysql で環境構築(初心者でも30分で完了!)
https://www.youtube.com/watch?v=Fq1PH0Gwi8I

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?