{"id":7078,"date":"2021-08-02T06:53:46","date_gmt":"2021-08-01T21:53:46","guid":{"rendered":"https:\/\/yumishin.com\/?p=7078"},"modified":"2021-08-02T06:53:46","modified_gmt":"2021-08-01T21:53:46","slug":"docker","status":"publish","type":"post","link":"https:\/\/yumishin.com\/?p=7078","title":{"rendered":"\u3010Rails, Docker, Postgres\u3011\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306e\u5909\u66f4\u304cDocker\u30b3\u30f3\u30c6\u30ca\u306b\u5373\u6642\u53cd\u6620\u3055\u308c\u306a\u3044"},"content":{"rendered":"<p>\u4eca\u56de\u306fdocker\u30b3\u30f3\u30c6\u30ca\u3067\u306e\u5909\u66f4\u304cvscode\u3084Atom\u3068\u3044\u3063\u305f\u30a8\u30c7\u30a3\u30bf\u4e0a\u306b\u5373\u6642\u53cd\u6620\u3055\u308c\u306a\u3044\u3068\u8a00\u3046\u72b6\u6cc1\u3092\u6271\u3044\u307e\u3059\u3002<\/p>\n<p>\u9006\u306bvscode\u306a\u3069\u306e\u30a8\u30c7\u30a3\u30bf\u4e0a\u3067\u306e\u5909\u66f4\u304c\u5373\u6642docker\u30b3\u30f3\u30c6\u30ca\u306b\u53cd\u6620\u3055\u308c\u306a\u3044\u3068\u8a00\u3046\u5834\u5408\u3082\u5bfe\u8c61\u3067\u3059\u3002\u305d\u308c\u3067\u306f\u539f\u56e0\u3068\u5bfe\u51e6\u6cd5\u306b\u3064\u3044\u3066\u307e\u3068\u3081\u3066\u304a\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h2 id=\"i-0\">\u3010Rails, Docker, Postgres\u3011\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306e\u5909\u66f4\u304cDocker\u30b3\u30f3\u30c6\u30ca\u306b\u53cd\u6620\u3055\u308c\u306a\u3044<\/h2>\n<h3 id=\"i-1\">\u7d50\u8ad6<\/h3>\n<p>docker-compose.yml\u306evolumes\u306b\u6307\u5b9a\u3055\u308c\u3066\u3044\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304c\u3001Dockerfile\u3067\u4f5c\u6210\u3057\u305f\u4f5c\u696d\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u540d\u3068\u7570\u306a\u3063\u3066\u3044\u308b\u306e\u304c\u539f\u56e0\u3067\u3059\u3002\uff08\u79c1\u306e\u5834\u5408\u306e\u539f\u56e0\u306f\u3053\u308c\u3067\u3057\u305f\u3002\uff09<\/p>\n<p>\u306a\u306e\u3067\u3001docker-compose.yml\u306evolumes\u306b\u6307\u5b9a\u3057\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u540d\u524d\u3068\u3001Dockerfile\u3067\u4f5c\u6210\u3057\u3066\u3044\u308b\u4f5c\u696d\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u540d\u524d\u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3 id=\"i-2\">\u8a73\u7d30<\/h3>\n<p>\u79c1\u306e\u306f\u307e\u3063\u305f\u4e8b\u4f8b\u3067\u3059\u3002<\/p>\n<p><strong>docker-compose.yml<\/strong><\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30b3\u30fc\u30c9<\/span><\/p>\n<pre><code>version: '3'\nservices:\n  db:\n    image: mysql:5.7\n    environment:\n      MYSQL_ROOT_PASSWORD: password\n      MYSQL_DATABASE: root\n    ports:\n      - \"3306:3306\"\n\n  web:\n    build: .\n    command: rails s -p 3000 -b '0.0.0.0'\n    volumes:\n      - .:\/app_name <span style=\"color: #ff0000;\">\u203b\u3053\u3053\u306e\u8a18\u8ff0\u304c\u30dd\u30a4\u30f3\u30c8<\/span>\n    ports:\n      - \"3000:3000\"\n    links:\n      - db<\/code><\/pre>\n<\/div>\n<p><strong>dockerfile<\/strong><\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> \u30b3\u30fc\u30c9<\/span><\/p>\n<pre><code>FROM ruby:2.5.3\n\n# \u5fc5\u8981\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\uff08\u57fa\u672c\u7684\u306b\u5fc5\u8981\u306b\u306a\u3063\u3066\u304f\u308b\u3082\u306e\u3060\u3068\u601d\u3046\u306e\u3067\u524a\u3089\u306a\u3044\u3053\u3068\uff09\nRUN apt-get update -qq &amp;&amp; \\\n    apt-get install -y build-essential \\ \n                       libpq-dev \\        \n                       nodejs           \n\n# \u4f5c\u696d\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u4f5c\u6210\u3001\u8a2d\u5b9a\nRUN mkdir \/app_name <span style=\"color: #ff0000;\">\u203b\u3053\u3053\u3067\u4f5c\u6210\u3057\u305f\u4f5c\u696d\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u540d\u304c\u30dd\u30a4\u30f3\u30c8<\/span>\n##\u4f5c\u696d\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u540d\u3092APP_ROOT\u306b\u5272\u308a\u5f53\u3066\u3066\u3001\u4ee5\u4e0b$APP_ROOT\u3067\u53c2\u7167\nENV APP_ROOT \/app_name \nWORKDIR $APP_ROOT\n\n# \u30db\u30b9\u30c8\u5074\uff08\u30ed\u30fc\u30ab\u30eb\uff09\u306eGemfile\u3092\u8ffd\u52a0\u3059\u308b\uff08\u30ed\u30fc\u30ab\u30eb\u306eGemfile\u306f\u3010\uff13\u3011\u3067\u4f5c\u6210\uff09\nADD .\/Gemfile $APP_ROOT\/Gemfile\nADD .\/Gemfile.lock $APP_ROOT\/Gemfile.lock\n\n# Gemfile\u306ebundle install\nRUN bundle install\nADD . $APP_ROOT<\/code><\/pre>\n<\/div>\n<p>\u7d50\u8ad6\u304b\u3089\u8a00\u3046\u3068\u3001docker-compose.yml\u306evolumes\u306b\u8a18\u8f09\u3057\u3066\u3044\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u540d\u3068\u3001Dockerfile\u306e\u4f5c\u696d\u7528\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u540d\u304c\u9055\u3063\u3066\u3044\u308b\u3068\u3001\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u5373\u6642\u53cd\u6620\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>docker-compose build\u3057\u3066\u4f5c\u308a\u76f4\u305b\u3070\u53cd\u6620\u3055\u308c\u308b\u306e\u3067\u3059\u304c\u3001\u305d\u308c\u3060\u3068\u9762\u5012\u3067\u3059\u3088\u306d\u3002<\/p>\n<div class=\"memo \">\n<div class=\"memo_ttl dfont\"> MEMO<\/div>\n<p>\u3061\u306a\u307f\u306bdocker-compose.yml\u306evolumes\u306e<code>- . : app_name<\/code>\u306e\u610f\u5473\u3067\u3059\u304c\u3001\u30ab\u30ec\u30f3\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5185\u5bb9\u3092\u30b3\u30f3\u30c6\u30ca\u306eapp_name\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u53cd\u6620\u3055\u305b\u308b\u3068\u8a00\u3046\u610f\u5473\u3067\u3059\u3002<\/p>\n<p>\u3053\u3053\u3067\u3044\u3046\u30ab\u30ec\u30f3\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306f\u3001docker-compose\u30b3\u30de\u30f3\u30c9\u3092\u8a18\u8ff0\u3059\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u6307\u3057\u307e\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3082\u3057Dockerfile\u3067\u4f5c\u6210\u3057\u3066\u3044\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u540d\u304cdocker-compose.yml\u3067\u8a18\u8f09\u3057\u3066\u3044\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u540d\u3068\u9055\u3046\u3068\u3001\u3046\u307e\u304f\u53cd\u6620\uff08\u30de\u30a6\u30f3\u30c8\uff09\u3067\u304d\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<\/div>\n<p>\u3068\u8a00\u3046\u3053\u3068\u3067\u3057\u305f\uff01\u3046\u307e\u304f\u4f1d\u308f\u308a\u307e\u3057\u305f\u304b\u306d\uff1f\u308f\u304b\u3089\u306a\u3044\u3053\u3068\u304c\u3042\u308c\u3070\u3001\u3054\u9023\u7d61\u304f\u3060\u3055\u3044\uff01<\/p>\n<p>\u3057\u3070\u3089\u304f\u306f\u307e\u308a\u307e\u3057\u305f\u3002\u3002\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u56de\u306fdocker\u30b3\u30f3\u30c6\u30ca\u3067\u306e\u5909\u66f4\u304cvscode\u3084Atom\u3068\u3044\u3063\u305f\u30a8\u30c7\u30a3\u30bf\u4e0a\u306b\u5373\u6642\u53cd\u6620\u3055\u308c\u306a\u3044\u3068\u8a00\u3046\u72b6\u6cc1\u3092\u6271\u3044\u307e\u3059\u3002 \u9006\u306bvscode\u306a\u3069\u306e\u30a8\u30c7\u30a3\u30bf\u4e0a\u3067\u306e\u5909\u66f4\u304c\u5373\u6642docker\u30b3\u30f3\u30c6\u30ca\u306b\u53cd\u6620\u3055\u308c\u306a\u3044\u3068\u8a00\u3046\u5834\u5408\u3082\u5bfe\u8c61\u3067\u3059\u3002 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":7090,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[256],"tags":[],"class_list":["post-7078","post","type-post","status-publish","format-standard","has-post-thumbnail","category-it","entry"],"_links":{"self":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/7078","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7078"}],"version-history":[{"count":3,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/7078\/revisions"}],"predecessor-version":[{"id":7091,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/7078\/revisions\/7091"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/media\/7090"}],"wp:attachment":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}