Docker/実践
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
&tag(Docker/実践);
*目次 [#nfebf151]
#contents
*関連ページ [#u1a0a84a]
*参考情報 [#ya9a5530]
*RailsをDockerで動かす [#ndef635d]
-公式ガイド[[Quickstart: Compose and Rails - Docker:https...
**プロジェクトの作成 [#s6b01b5e]
-Dockerfileを作成する(webサーバー用)
#pre{{
FROM ruby:2.3.3
RUN apt-get update -qq && apt-get install -y build-essent...
RUN mkdir /myapp
WORKDIR /myapp
ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
ADD . /myapp
}}
-同じフォルダにGemfileを作成
#pre{{
source 'https://rubygems.org'
gem 'rails', '5.0.0.1'
}}
-同じフォルダにGemfile.lockを作成
#pre{{
touch Gemfile.lock
}}
-docker-compose.ymlを作成。webコンテナはdepends_onでdbコ...
#pre{{
version: '2'
services:
db:
image: postgres
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
}}
**プロジェクトのビルド [#mcdaa46b]
-以下のコマンドでRailsスケルトンアプリを実行。
#pre{{
docker-compose run web rails new . --force --database=pos...
}}
-composeによってwebイメージが作られる。rails newがコンテ...
-Gemfileを変更したときは「docker-compose build」を実行。
**データベースとの接続 [#k500c382]
-config/database.ymlの作成
#pre{{
development: &default
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
username: postgres
password:
host: db
test:
<<: *default
database: myapp_test
}}
-起動
docker-compose up
-他のターミナルを開きdb生成
docker compose run web rake db:create
**トラブルシューティング [#y996932e]
***server is already running [#t10e0a9f]
-[[RailsアプリケーションをDockerを使って開発する、ほとん...
-[[Rails server is still running in a new opened docker c...
-server.pidファイルが残っている場合、それを削除する。
-上のサンプルの場合tmp/pids/server.pidを確認。
-次の方法もあり?
command: /bin/sh -c "rm -f tmp/pids/server.pid && rails ...
**サーバーは動いているけどページが表示されない [#f20a3d13]
-[[DockerでRailsの開発環境つくったらweb-console動かない -...
-config/environments/development.rbに以下を追加
config.web_console.whitelisted_ips = '0.0.0.0/0'
終了行:
&tag(Docker/実践);
*目次 [#nfebf151]
#contents
*関連ページ [#u1a0a84a]
*参考情報 [#ya9a5530]
*RailsをDockerで動かす [#ndef635d]
-公式ガイド[[Quickstart: Compose and Rails - Docker:https...
**プロジェクトの作成 [#s6b01b5e]
-Dockerfileを作成する(webサーバー用)
#pre{{
FROM ruby:2.3.3
RUN apt-get update -qq && apt-get install -y build-essent...
RUN mkdir /myapp
WORKDIR /myapp
ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
ADD . /myapp
}}
-同じフォルダにGemfileを作成
#pre{{
source 'https://rubygems.org'
gem 'rails', '5.0.0.1'
}}
-同じフォルダにGemfile.lockを作成
#pre{{
touch Gemfile.lock
}}
-docker-compose.ymlを作成。webコンテナはdepends_onでdbコ...
#pre{{
version: '2'
services:
db:
image: postgres
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
}}
**プロジェクトのビルド [#mcdaa46b]
-以下のコマンドでRailsスケルトンアプリを実行。
#pre{{
docker-compose run web rails new . --force --database=pos...
}}
-composeによってwebイメージが作られる。rails newがコンテ...
-Gemfileを変更したときは「docker-compose build」を実行。
**データベースとの接続 [#k500c382]
-config/database.ymlの作成
#pre{{
development: &default
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
username: postgres
password:
host: db
test:
<<: *default
database: myapp_test
}}
-起動
docker-compose up
-他のターミナルを開きdb生成
docker compose run web rake db:create
**トラブルシューティング [#y996932e]
***server is already running [#t10e0a9f]
-[[RailsアプリケーションをDockerを使って開発する、ほとん...
-[[Rails server is still running in a new opened docker c...
-server.pidファイルが残っている場合、それを削除する。
-上のサンプルの場合tmp/pids/server.pidを確認。
-次の方法もあり?
command: /bin/sh -c "rm -f tmp/pids/server.pid && rails ...
**サーバーは動いているけどページが表示されない [#f20a3d13]
-[[DockerでRailsの開発環境つくったらweb-console動かない -...
-config/environments/development.rbに以下を追加
config.web_console.whitelisted_ips = '0.0.0.0/0'
ページ名: