質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

1回答

2221閲覧

rails new デフォルトのファイルが生成されない

sakusaka

総合スコア14

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2020/07/25 13:33

編集2020/07/25 14:21

現在、DockerでRails+nginxで開発環境を構築しようとしているのですが、
デフォルトのファイルが生成されません。

もしよろしければご教授いただけると助かります。
どうぞよろしくおねがいします。


実行コマンドはこちら

docker run --rm rails-app rails new . -G --force --database=mysql --skip-bundle

実行結果はこちら

log

1$ docker run --rm rails-app rails new . -G --force --database=mysql --skip-bundle 2 exist 3 create README.md 4 create Rakefile 5 create .ruby-version 6 create config.ru 7 force Gemfile 8 create package.json 9 create app 10 create app/assets/config/manifest.js 11 create app/assets/javascripts/application.js 12 create app/assets/javascripts/cable.js 13 create app/assets/stylesheets/application.css 14 create app/channels/application_cable/channel.rb 15 create app/channels/application_cable/connection.rb 16 create app/controllers/application_controller.rb 17 create app/helpers/application_helper.rb 18 create app/jobs/application_job.rb 19 create app/mailers/application_mailer.rb 20 create app/models/application_record.rb 21 create app/views/layouts/application.html.erb 22 create app/views/layouts/mailer.html.erb 23 create app/views/layouts/mailer.text.erb 24 create app/assets/images/.keep 25 create app/assets/javascripts/channels 26 create app/assets/javascripts/channels/.keep 27 create app/controllers/concerns/.keep 28 create app/models/concerns/.keep 29 create bin 30 create bin/bundle 31 create bin/rails 32 create bin/rake 33 create bin/setup 34 create bin/update 35 create bin/yarn 36 create config 37 create config/routes.rb 38 create config/application.rb 39 create config/environment.rb 40 create config/cable.yml 41 create config/puma.rb 42 create config/spring.rb 43 create config/storage.yml 44 create config/environments 45 create config/environments/development.rb 46 create config/environments/production.rb 47 create config/environments/test.rb 48 create config/initializers 49 create config/initializers/application_controller_renderer.rb 50 create config/initializers/assets.rb 51 create config/initializers/backtrace_silencers.rb 52 create config/initializers/content_security_policy.rb 53 create config/initializers/cookies_serializer.rb 54 create config/initializers/cors.rb 55 create config/initializers/filter_parameter_logging.rb 56 create config/initializers/inflections.rb 57 create config/initializers/mime_types.rb 58 create config/initializers/new_framework_defaults_5_2.rb 59 create config/initializers/wrap_parameters.rb 60 create config/locales 61 create config/locales/en.yml 62 create config/master.key 63/usr/local/bundle/gems/activesupport-5.2.4.3/lib/active_support/message_encryptor.rb:175: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call 64/usr/local/bundle/gems/activesupport-5.2.4.3/lib/active_support/messages/metadata.rb:17: warning: The called method `wrap' is defined here 65 create config/boot.rb 66 create config/database.yml 67 create db 68 create db/seeds.rb 69 create lib 70 create lib/tasks 71 create lib/tasks/.keep 72 create lib/assets 73 create lib/assets/.keep 74 create log 75 create log/.keep 76 create public 77 create public/404.html 78 create public/422.html 79 create public/500.html 80 create public/apple-touch-icon-precomposed.png 81 create public/apple-touch-icon.png 82 create public/favicon.ico 83 create public/robots.txt 84 create tmp 85 create tmp/.keep 86 create tmp/pids 87 create tmp/pids/.keep 88 create tmp/cache 89 create tmp/cache/assets 90 create vendor 91 create vendor/.keep 92 create test/fixtures 93 create test/fixtures/.keep 94 create test/fixtures/files 95 create test/fixtures/files/.keep 96 create test/controllers 97 create test/controllers/.keep 98 create test/mailers 99 create test/mailers/.keep 100 create test/models 101 create test/models/.keep 102 create test/helpers 103 create test/helpers/.keep 104 create test/integration 105 create test/integration/.keep 106 create test/test_helper.rb 107 create test/system 108 create test/system/.keep 109 create test/application_system_test_case.rb 110 create storage 111 create storage/.keep 112 create tmp/storage 113 create tmp/storage/.keep 114 remove config/initializers/cors.rb 115 remove config/initializers/new_framework_defaults_5_2.rb

Dockerfileがこちらです

FROM ruby:2.7.1 # install tools RUN apt-get update \ && apt-get install -y --no-install-recommends \ apt-transport-https \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # install yarn RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list RUN apt-get update \ && apt-get -y install yarn \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* RUN yarn add --dev webpack-dev-server # install node 10.x RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - RUN apt-get install -y nodejs \ && apt-get clean RUN mkdir /myapp WORKDIR /myapp ADD Gemfile /myapp/Gemfile ADD Gemfile.lock /myapp/Gemfile.lock RUN bundle install COPY . /myapp

k8s yaml

--- # コンテナ apiVersion: apps/v1 kind: Deployment metadata: name: mybotapp spec: replicas: 1 selector: matchLabels: app: mybotapp template: metadata: labels: app: mybotapp spec: containers: - name: rails-container image: rails-app:latest imagePullPolicy: Never volumeMounts: - mountPath: /app/tmp/sockets name: web-sock - mountPath: /app name: src command: ["/bin/sh","-c"] args: ["bundle exec pumactl start"] env: - name: TZ value: Asia/Tokyo - name: nginx-container image: nginx:1.13.3 imagePullPolicy: Never ports: - name: http-server containerPort: 80 - name: https-server containerPort: 443 volumeMounts: - mountPath: /app/tmp/sockets name: web-sock - mountPath: /maintenance name: nginx-maintenance-volume #- mountPath: /etc/nginx/params # readOnly: true # name: nginx-params-config imagePullSecrets: - name: ap-northeast-1-ecr-registry volumes: - name: web-assets emptyDir: {} - name: web-sock emptyDir: {} - name: nginx-maintenance-volume hostPath: # 作業者にあわせてパスを変更 path: $PWD/myapp/public type: Directory #- name: nginx-params-config # configMap: # name: nginx-params-config # items: # - key: ip-allow # path: ip-allow - name: src hostPath: # 作業者にあわせてパスを変更 path: "$PWD/myapp" type: DirectoryOrCreate コード

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

volume を bind していないため
ファイルがコンテナ内で生成された後、コンテナ終了と同時に消えています

次のコマンドを実行すると、現在のディレクトリーに rails new で生成されたファイルが出力されます:

console

1docker run -v $(pwd):/myapp --rm rails-app rails new . -G --force --database=mysql --skip-bundle

現在のディレクトリーにある Gemfile などが上書きされることに注意してください

console

1-v $(pwd):/myapp

上記のオプションの追加により
現在のディレクトリーがコンテナに bind されるため、
rails new で生成されたファイルがホスト側に出力されるようになります

投稿2020/07/25 13:55

編集2020/07/26 13:11
y_shinoda

総合スコア3272

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

sakusaka

2020/07/25 14:19

すみません。失礼しました。 kubernetesのyamlファイルもあり、記載が漏れていました。 上記修正させていただきました。
y_shinoda

2020/07/25 15:24

kubernetes は関係ないのではありませんか? > デフォルトのファイル が指しているのは Rails のアプリケーションコードのことですよね? なにかの教材をやっていらっしゃるのであれば その教材が何をやろうとしているのかをよく確認してみてください Dockerfile に ADD Gemfile.lock /myapp/Gemfile.lock という行があるので 質問欄のコマンドを実行する作業は rails new でファイルを出力してビルドし直す工程であると思われます kubernetes はビルドや CI には使われません
sakusaka

2020/07/25 15:48

あ、、、勘違いしました。 k8sを起動する際にアプリケーションコードが無いので、エラーになり、 まずは、rails newしようと思い、試行錯誤していたところで、 混乱してしまいました。 ちなみに、こういう場合、rails podが起動しないため、 rails new できないのですが、この場合、どういう風に やるのがベターなのでしょうか。
y_shinoda

2020/07/25 16:04

質問欄のコマンドに回答欄のオプションを足して実行すると rails new でできた Rails アプリケーションのコードが入手できるので、 その状態で Dockerfile からイメージを再ビルドします ↓ ほぼ同様の手順であるこちらの記事を参考にすると良いかもしれません (Docker Compose ですが) https://docs.docker.com/compose/rails/
sakusaka

2020/07/26 01:16

ありがとうございます! オプショを追加して生成できたのですが、なぜかtmpフォルダのみ生成されました。 質問でも記載させていただいている、下記のエラーが起因でしょうか。 /usr/local/bundle/gems/activesupport-5.2.4.3/lib/active_support/message_encryptor.rb:175: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /usr/local/bundle/gems/activesupport-5.2.4.3/lib/active_support/messages/metadata.rb:17: warning: The called method `wrap' is defined here
y_shinoda

2020/07/26 02:22

こちらで試したところ、同じ警告は出ましたがファイルは出力されました ちなみにこちらの環境は Windows 10 Pro です Windows の場合はオプションは -v $(pwd -W):/myapp です または、Docker Compose を使うと bind するパスを相対パスで記述できます Windows 10 17.09 以前の WSL 環境の場合、 正しくファイルが出力されない不具合があることも報告されています その場合は Windows Update を行った方が良いでしょう https://teratail.com/questions/277106#reply-394826
sakusaka

2020/07/26 08:49

こちらは、Mac環境で実施しました。 んー、もう少し試してみます。
sakusaka

2020/07/26 13:05

こちら解決できました! -v オプションを後ろにつけると動かないようです。 ありがとうございました。
y_shinoda

2020/07/26 13:15

回答に反映しておきました、 回答時に手元で確認できない状態だったため確証が持てず コマンド全体を記述しなかったことが原因で 混乱させてしまったようで失礼しました
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問