LoginSignup
10
7

More than 5 years have passed since last update.

windows 10でdockerを使ってruby 2.5.0 rails 5開発環境を構築する、ファイルの共有

Last updated at Posted at 2018-03-11

今回使ったPC

Think Pad
windows 10
Intel Core i3-4000M 2.40GHz以上
メモリ: 4GB以上
ストレージ 128GB以上

キャプチャ.PNG

dockerとは

README FIRST for Docker Toolbox and Docker Machine users: Docker for Windows requires Microsoft Hyper-V to run. The Docker for Windows installer enables Hyper-V for you, if needed, and restart your machine. After Hyper-V is enabled, VirtualBox no longer works, but any VirtualBox VM images remain. VirtualBox VMs created with docker-machine (including the default one typically created during Toolbox install) no longer start. These VMs cannot be used side-by-side with Docker for Windows. However, you can still use docker-machine to manage remote VMs.

Hyper-Vが入っていないPCだと少し大変

手順

a. アカウント名をチェック
英語で表記"C:/User//"User Name部分に英語表記以外が存在するとdocker-composeコマンドが使えないことがある。
英語以外の場合、新しいユーザーを作成し、それからb.以降を始める
手順は下記参考
https://pc-karuma.net/windows10-create-local-account/

b. BIOSでVirtualization Techologyをonにする
See these instructions to install Hyper-V manually. A reboot is required. If you install Hyper-V without the reboot, Docker for Windows does not work correctly. On some systems, Virtualization needs to be enabled in the BIOS. The steps to do so are Vendor specific, but typically the BIOS option is called Virtualization Technology (VTx) or similar.
手順は下記参考。メーカーによりBIOSの設定が違うので、「メーカー名 BIOS Virtualization Technology」などでググる
https://freesoft.tvbok.com/win10/access_uefi_bios_setup.html

c. (Hyper-Vが入っている場合)Hyper-VをOnにする。

d. download&install docker
if Hyper-Vが入っている場合
https://docs.docker.com/docker-for-windows/install/
if Hyper-Vが入っていない場合
https://docs.docker.com/toolbox/toolbox_install_windows/

ダウンロードしたら、デスクトップに
Docker Quickstart Terminal
が追加されるのでクリックして起動する。

e. 環境変数、COMPOSE_CONVERT_WINDOWS_PATHS に 1を設定する。
下記参考
https://qiita.com/asami-H-Ishi/items/5a6bb2102b3a07cbab41

f. サンプルのアプリをclone
(githubにアカウントを作ってログインする)
git clone https://github.com/akihitoalextsuboi/docker-rails.git

g. dockerを立ち上げ
cd docker-rails
docker-compose run web rails new . --force --database=postgresql
docker-compose build
docker-compose up

h. 192.168.99.100:3000にアクセス

i. 終了はdocker-compose downまたはControl+C
Control+C でやると再起動時にこのエラーが出る
web_1 | A server is already
running. Check /myapp/tmp/pids/server.pid.
To resolve this, delete the file tmp/pids/server.pid, and then re-start the application with docker-compose up.
rm tmp/pids/server.pid

j. dockerにログインする方法
docker-compose exec web bash

注意
docker-composeファイルのように書けばファイルは共有される
https://docs.docker.com/compose/rails/

* windowsでdocker-composeが使えないときがある
COMPOSE_CONVERT_WINDOWS_PATHS に 1 

複数ターミナルを開く方法は新しく、docker quick terminalのwindowを開くしかなさそう

参考
https://docs.docker.com/compose/rails/#more-compose-documentation
https://nulab-inc.com/ja/blog/typetalk/docker-tutorial-local-environment-team/
https://qiita.com/tomomomo1217/items/3e9664fd5290934f0815

https://qiita.com/acro5piano/items/ac3bef8a9f8bb9fdbdd5
https://qiita.com/KeitaMoromizato/items/ae1a57fc62b41b942d71

10
7
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
10
7