実現したいこと
Udemyの講座で作成したDockerデスクトップ+Ruby on RailsアプリをXServerVPS上のDockerで動かす方法について知りたいです。
発生している問題・分からないこと
現在Windowsパソコン上でDockerデスクトップをインストールし、その上でRuby on Railsアプリを動かしています(Udemyの学習コースにあるサンプルアプリ)。
このアプリをVPS上のDockerで動かしてみたいと考え、XServer VPSをレンタルしました。
ネット情報を参考に、SSHでVPSにアクセスし、Docker(エンジン?)をインストールするところまではできました。「Hello from Docker!」の表示まではできるようになっています。
しかし、この次に何をやったらいいのか見当がつきません。
1)Docker上でRubyとRailsをインストールする。
2)DockerfileとDockercompose.ymlとDatabase.ymlを作成または編集して、設定する。
という流れでいいのでしょうか。
また、DockerfileとDockercompose.ymlとDatabase.ymlの設定はパソコン上でDockerデスクトップを使った場合とどのように異なるのでしょうか。
誠に恐れ入りますが、アドバイスを頂ければありがたく存じます。
なお、パソコン上の各ファイルの設定は以下のようになっています。
該当のソースコード
Dockerfile
1# ベースとして使用するイメージ名(DockerHubからダウンロードされる) 2FROM ruby:3.2.2-alpine 3 4# 利用可能なパッケージのリストを更新するコマンドを実行 5RUN apk update 6 7# パッケージをインストールするコマンドを実行 8RUN apk add g++ make mysql-dev tzdata mysql-client 9#UN apk add g++ make mysql-dev tzdata 10 11# コンテナを起動した時の作業ディレクトリを/appにする 12WORKDIR /app 13 14# PC上のGemfile を .(/app)にコピー 15COPY Gemfile . 16 17# bundle installでGemfileに記述されているgemをインストール 18RUN bundle install
docker
1version: "3" 2services: 3 web: 4 build: . 5 command: sh -c "rm -f tmp/pids/server.pid && rails s -p 3000 -b '0.0.0.0'" 6 volumes: 7 - .:/app 8 ports: 9 - 3000:3000 10 depends_on: 11 - db 12 db: 13 image: mysql:8.0 14 volumes: 15 - db-volume:/var/lib/mysql 16 environment: 17 MYSQL_ROOT_PASSWORD: password 18volumes: 19 db-volume: 20
Gemfile
1source "https://rubygems.org" 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby "3.2.2" 5 6# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" 7gem "rails", "~> 7.0.6" 8#gem "rails", "~> 7.0.6" 9 10# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] 11gem "sprockets-rails" 12 13# Use mysql as the database for Active Record 14gem "mysql2", "~> 0.5" 15#gem "mysql2", "~> 0.5" 16 17# Use the Puma web server [https://github.com/puma/puma] 18gem "puma", "~> 5.0" 19 20# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] 21gem "importmap-rails" 22 23# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] 24gem "turbo-rails" 25 26# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] 27gem "stimulus-rails" 28 29# Build JSON APIs with ease [https://github.com/rails/jbuilder] 30gem "jbuilder" 31 32# Use Redis adapter to run Action Cable in production 33# gem "redis", "~> 4.0" 34 35# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] 36# gem "kredis" 37 38# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] 39# gem "bcrypt", "~> 3.1.7" 40 41# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 42gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] 43 44# Reduces boot times through caching; required in config/boot.rb 45gem "bootsnap", require: false 46 47# Use Sass to process CSS 48# gem "sassc-rails" 49 50# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] 51# gem "image_processing", "~> 1.2" 52 53group :development, :test do 54 # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem 55 gem "debug", platforms: %i[ mri mingw x64_mingw ] 56end 57 58group :development do 59 # Use console on exceptions pages [https://github.com/rails/web-console] 60 gem "web-console" 61 62 # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] 63 # gem "rack-mini-profiler" 64 65 # Speed up commands on slow machines / big apps [https://github.com/rails/spring] 66 # gem "spring" 67end 68 69
database.yml
1# MySQL. Versions 5.5.8 and up are supported. 2# 3# Install the MySQL driver 4# gem install mysql2 5# 6# Ensure the MySQL gem is defined in your Gemfile 7# gem "mysql2" 8# 9# And be sure to use new-style password hashing: 10# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html 11# 12default: &default 13 adapter: mysql2 14 encoding: utf8mb4 15 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 16 username: root 17 password: password 18 host: db 19 20development: 21 <<: *default 22 database: app_development 23 24# Warning: The database defined as "test" will be erased and 25# re-generated from your development database when you run "rake". 26# Do not set this db to the same as development or production. 27test: 28 <<: *default 29 database: app_test 30 31# As with config/credentials.yml, you never want to store sensitive information, 32# like your database password, in your source code. If your source code is 33# ever seen by anyone, they now have access to your database. 34# 35# Instead, provide the password or a full connection URL as an environment 36# variable when you boot the app. For example: 37# 38# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" 39# 40# If the connection URL is provided in the special DATABASE_URL environment 41# variable, Rails will automatically merge its configuration values on top of 42# the values provided in this file. Alternatively, you can specify a connection 43# URL environment variable explicitly: 44# 45# production: 46# url: <%= ENV["MY_APP_DATABASE_URL"] %> 47# 48# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database 49# for a full overview on how database connection configuration can be specified. 50# 51production: 52 <<: *default 53 database: app_production 54 username: app 55 password: <%= ENV["APP_DATABASE_PASSWORD"] %> 56
特になし
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
ネットで関連しそうな情報を調べたが、パソコンで動かした場合とサーバーのVPSで動かす場合で、設定や手順がどうことなるのかを記述したものが見つからなかった。
補足
特になし

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2024/07/04 12:44