実現したいこと
ローカルで作成したDocker上のRailsアプリをXserver VPS上のDocker上で動かしたいです。
発生している問題・分からないこと
VSCodeでRemote-sshを使い、サーバー上にDockerをインストールし、Railsをインストールしました。さらに、Dockerfile、dockercompose.yml、database.ymlをローカルからコピーして、DBもcreateしました。結果として、ブラウザから、VPS上のRailsのホーム画面を確認することができました。
ただ、この段階では、Railsのビュー、コントローラー、モデルやデーターベース構造などはローカルからコピーされていません。
Railsのビュー、コントローラー、モデルやデーターベース構造をローカルから一気にコピー(デプロイ?)するにはどのような方法をとるのが良いのでしょうか。
誠に恐れりますが、アドバイスを頂ければありがたく存じます。
該当のソースコード
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
dockerecompose.yml
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
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
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 9# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] 10gem "sprockets-rails" 11 12# Use mysql as the database for Active Record 13gem "mysql2", "~> 0.5" 14 15# Use the Puma web server [https://github.com/puma/puma] 16gem "puma", "~> 5.0" 17 18# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] 19gem "importmap-rails" 20 21# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] 22gem "turbo-rails" 23 24# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] 25gem "stimulus-rails" 26 27# Build JSON APIs with ease [https://github.com/rails/jbuilder] 28gem "jbuilder" 29 30# Use Redis adapter to run Action Cable in production 31# gem "redis", "~> 4.0" 32 33# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] 34# gem "kredis" 35 36# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] 37# gem "bcrypt", "~> 3.1.7" 38 39# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 40gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] 41 42# Reduces boot times through caching; required in config/boot.rb 43gem "bootsnap", require: false 44 45# Use Sass to process CSS 46# gem "sassc-rails" 47 48# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] 49# gem "image_processing", "~> 1.2" 50 51group :development, :test do 52 # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem 53 gem "debug", platforms: %i[ mri mingw x64_mingw ] 54end 55 56group :development do 57 # Use console on exceptions pages [https://github.com/rails/web-console] 58 gem "web-console" 59 60 # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] 61 # gem "rack-mini-profiler" 62 63 # Speed up commands on slow machines / big apps [https://github.com/rails/spring] 64 # gem "spring" 65end 66 67
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
私に理解できるような情報が見つかりませんでした。
補足
特になし

回答1件
あなたの回答
tips
プレビュー