{"id":7624,"date":"2022-01-17T06:04:16","date_gmt":"2022-01-16T21:04:16","guid":{"rendered":"https:\/\/yumishin.com\/?p=7624"},"modified":"2022-01-17T06:04:16","modified_gmt":"2022-01-16T21:04:16","slug":"rails7-on-docker","status":"publish","type":"post","link":"https:\/\/yumishin.com\/?p=7624","title":{"rendered":"Rails7 on Docker"},"content":{"rendered":"<p>\u4eca\u56de\u306f<code>Ruby3.0.3<\/code>\u3068<code>Rails7<\/code>\u3067<code>Docker<\/code>\u74b0\u5883\u3092\u4f5c\u3063\u3066\u307f\u305f\u306e\u3067\u3001\u305d\u306e\u6642\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u307e\u3068\u3081\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<h2 id=\"i-0\">Rails7 on Docker<\/h2>\n<p>\u3068\u308a\u3042\u3048\u305a\u624b\u9806\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<ol>\n<li><code>Rails7<\/code>\u3067\u30a2\u30d7\u30ea\u3092\u4f5c\u308b<\/li>\n<li>\u305d\u306e\u5f8c\u3001\u30a2\u30d7\u30ea\u306e\u30eb\u30fc\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u76f4\u4e0b\u306b<code>Dockerfile<\/code>\u3001<code>docker-compose.yml<\/code>\u3001<code>entrypoint.sh<\/code>\u3092\u4f5c\u3063\u3066\u3001\u5185\u5bb9\u3092\u8a18\u8ff0\u3059\u308b<\/li>\n<li><code>config\/database.yml<\/code>\u3092\u7de8\u96c6\u3059\u308b<\/li>\n<\/ol>\n<hr>\n<p>\u4ee5\u4e0b\u306f\u5404\u7a2e\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u3067\u3059\u3002<\/p>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> Dockerfile<\/span><\/p>\n<pre><code>FROM ruby:3.0.3\nRUN apt-get update -qq &amp;&amp; apt-get install -y nodejs postgresql-client\nRUN mkdir \/myapp\nWORKDIR \/myapp\nCOPY Gemfile \/myapp\/Gemfile\nCOPY Gemfile.lock \/myapp\/Gemfile.lock\nRUN bundle install\nCOPY . \/myapp\n\n# Add a script to be executed every time the container starts.\nCOPY entrypoint.sh \/usr\/bin\/\nRUN chmod +x \/usr\/bin\/entrypoint.sh\nENTRYPOINT [\"entrypoint.sh\"]\nEXPOSE 3000\n\n# Start the main process.\nCMD [\"rails\", \"server\", \"-b\", \"0.0.0.0\"]\n<\/code><\/pre>\n<\/div>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> docker-compose.yml<\/span><\/p>\n<pre><code>version: \"3.9\"\nservices:\n  db:\n    image: postgres\n    volumes:\n      - .\/tmp\/db:\/var\/lib\/postgresql\/data\n    environment:\n      POSTGRES_PASSWORD: password\n  web:\n    build: .\n    command: bash -c \"rm -f tmp\/pids\/server.pid &amp;&amp; bundle exec rails s -p 3000 -b '0.0.0.0'\"\n    volumes:\n      - .:\/myapp\n    ports:\n      - \"3000:3000\"\n    depends_on:\n      - db\n<\/code><\/pre>\n<\/div>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> entrypoint.sh<\/span><\/p>\n<pre><code>#!\/bin\/bash\nset -e\n\n# Remove a potentially pre-existing server.pid for Rails.\nrm -f \/myapp\/tmp\/pids\/server.pid\n\n# Then exec the container's main process (what's set as CMD in the Dockerfile).\nexec \"$@\"\n<\/code><\/pre>\n<\/div>\n<div class=\"pre_tag\"><span><i class=\"fa fa-code\"><\/i> config\/database.yml<\/span><\/p>\n<pre><code>default: &amp;default\n  adapter: postgresql\n  encoding: unicode\n  host: db\n  username: postgres\n  password: password\n  pool: 5\n\ndevelopment:\n  &lt;&lt;: *default\n  database: myapp_development\n\ntest:\n  &lt;&lt;: *default\n  database: myapp_test\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u56de\u306fRuby3.0.3\u3068Rails7\u3067Docker\u74b0\u5883\u3092\u4f5c\u3063\u3066\u307f\u305f\u306e\u3067\u3001\u305d\u306e\u6642\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u307e\u3068\u3081\u3066\u304a\u304d\u307e\u3059\u3002 Rails7 on Docker \u3068\u308a\u3042\u3048\u305a\u624b\u9806\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002 Rails7\u3067\u30a2\u30d7\u30ea\u3092\u4f5c\u308b \u305d\u306e\u5f8c &#8230; <\/p>\n","protected":false},"author":1,"featured_media":7662,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[256],"tags":[],"class_list":{"0":"post-7624","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-it","8":"entry"},"_links":{"self":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/7624","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=7624"}],"version-history":[{"count":3,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/7624\/revisions"}],"predecessor-version":[{"id":7713,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/posts\/7624\/revisions\/7713"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=\/wp\/v2\/media\/7662"}],"wp:attachment":[{"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yumishin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}