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

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

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

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

Docker

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

Q&A

解決済

1回答

1399閲覧

ローカルディレクトリにrails newをしてもファイルが存在しない

is02

総合スコア17

Ruby on Rails

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

Docker

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

0グッド

0クリップ

投稿2020/07/03 14:28

編集2020/07/04 10:20

公式ドキュメント通りに作っていったのですが、
docker-compose run web rails new . --force --no-deps --database=postgresqlを入力しても
ローカルディレクトリにappフォルダが生成されません。

docker-compose run web lsでコンテナ内にあるのか調べたのですが、生成されていませんでした。

考えられる原因はなんでしょうか?

公式ドキュメント
https://docs.docker.com/compose/rails/

追記

console

1Starting aaaa_db_1 ... done 2 exist 3 create README.md 4 create Rakefile 5 create config.ru 6 create .gitignore 7 force Gemfile 8 run git init from "." 9Initialized empty Git repository in /railbook/.git/ 10 create app 11 create app/assets/config/manifest.js 12 create app/assets/javascripts/application.js 13 create app/assets/javascripts/cable.js 14 create app/assets/stylesheets/application.css 15 create app/channels/application_cable/channel.rb 16 create app/channels/application_cable/connection.rb 17 create app/controllers/application_controller.rb 18 create app/helpers/application_helper.rb 19 create app/jobs/application_job.rb 20 create app/mailers/application_mailer.rb 21 create app/models/application_record.rb 22 create app/views/layouts/application.html.erb 23 create app/views/layouts/mailer.html.erb 24 create app/views/layouts/mailer.text.erb 25 create app/assets/images/.keep 26 create app/assets/javascripts/channels 27 create app/assets/javascripts/channels/.keep 28 create app/controllers/concerns/.keep 29 create app/models/concerns/.keep 30 create bin 31 create bin/bundle 32 create bin/rails 33 create bin/rake 34 create bin/setup 35 create bin/update 36 create bin/yarn 37 create config 38 create config/routes.rb 39 create config/application.rb 40 create config/environment.rb 41 create config/secrets.yml 42 create config/cable.yml 43 create config/puma.rb 44 create config/spring.rb 45 create config/environments 46 create config/environments/development.rb 47 create config/environments/production.rb 48 create config/environments/test.rb 49 create config/initializers 50 create config/initializers/application_controller_renderer.rb 51 create config/initializers/assets.rb 52 create config/initializers/backtrace_silencers.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_1.rb 59 create config/initializers/wrap_parameters.rb 60 create config/locales 61 create config/locales/en.yml 62 create config/boot.rb 63 create config/database.yml 64 create db 65 create db/seeds.rb 66 create lib 67 create lib/tasks 68 create lib/tasks/.keep 69 create lib/assets 70 create lib/assets/.keep 71 create log 72 create log/.keep 73 create public 74 create public/404.html 75 create public/422.html 76 create public/500.html 77 create public/apple-touch-icon-precomposed.png 78 create public/apple-touch-icon.png 79 create public/favicon.ico 80 create public/robots.txt 81 create test/fixtures 82 create test/fixtures/.keep 83 create test/fixtures/files 84 create test/fixtures/files/.keep 85 create test/controllers 86 create test/controllers/.keep 87 create test/mailers 88 create test/mailers/.keep 89 create test/models 90 create test/models/.keep 91 create test/helpers 92 create test/helpers/.keep 93 create test/integration 94 create test/integration/.keep 95 create test/test_helper.rb 96 create test/system 97 create test/system/.keep 98 create test/application_system_test_case.rb 99 create tmp 100 create tmp/.keep 101 create tmp/cache 102 create tmp/cache/assets 103 create vendor 104 create vendor/.keep 105 create package.json 106 remove config/initializers/cors.rb 107 remove config/initializers/new_framework_defaults_5_1.rb 108 run bundle install 109Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle 110as root will break this application for all non-root users on this machine. 111The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`. 112Fetching gem metadata from https://rubygems.org/............ 113Fetching gem metadata from https://rubygems.org/. 114Resolving dependencies... 115Bundler could not find compatible versions for gem "railties": 116 In snapshot (Gemfile.lock): 117 railties (= 5.1.5) 118 119 In Gemfile: 120 rails (~> 5.1.5) was resolved to 5.1.5, which depends on 121 railties (= 5.1.5) 122 123 sass-rails (~> 5.0) was resolved to 5.1.0, which depends on 124 railties (>= 5.2.0) 125 126Running `bundle update` will rebuild your snapshot from scratch, using only 127the gems in your Gemfile, which may resolve the conflict. 128 129Bundler could not find compatible versions for gem "sprockets": 130 In snapshot (Gemfile.lock): 131 sprockets (= 4.0.2) 132 133 In Gemfile: 134 sass-rails (~> 5.0) was resolved to 5.0.7, which depends on 135 sprockets (< 4.0, >= 2.8) 136 137 rails (~> 5.1.5) was resolved to 5.1.5, which depends on 138 sprockets-rails (>= 2.0.0) was resolved to 3.2.1, which depends on 139 sprockets (>= 3.0.0) 140 141Running `bundle update` will rebuild your snapshot from scratch, using only 142the gems in your Gemfile, which may resolve the conflict. 143 run bundle exec spring binstub --all 144bundler: command not found: spring 145Install missing gem executables with `bundle install`

フォルダの名前を「myapp」以外にすると、このようなログが出力されます。
myappの部分をすべて任意の名前のフォルダ名に変更したのですが、なぜこのような現象が起きるのでしょうか。

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

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

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

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

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

technocore

2020/07/03 14:45

>ローカルディレクトリにappフォルダが生成されません。 フォルダ名「app」をどこで指定しているのですか?
is02

2020/07/03 14:52

すみません、質問の質が悪すぎました。 rails newした時にたくさんでてくるフォルダが出ないという意味です
y_shinoda

2020/07/04 03:18

コマンド実行したときの標準出力、エラーメッセージを 次の記法で追記お願いします: ```console ここに記載 ```
y_shinoda

2020/07/04 03:20

上記はこちらではなく質問欄に追記お願いします
is02

2020/07/04 10:22

ご返信が遅くなってしまい、大変申し訳ございません。 今、追記いたしました。 また、公式ドキュメントの通り、フォルダ名を「myapp」にして実行した場合は問題なくファイルが出現しました。
guest

回答1

0

ベストアンサー

元の回答

参照している公式ドキュメントのすぐ下に書いてあるように、
フォルダは生成されません
ファイルは docker-compose.yml などと同階層に作成されます

Quickstart: Compose and Rails | Docker Documentation

console

1$ ls -l 2total 64 3-rw-r--r-- 1 vmb staff 222 Jun 7 12:05 Dockerfile 4-rw-r--r-- 1 vmb staff 1738 Jun 7 12:09 Gemfile 5-rw-r--r-- 1 vmb staff 4297 Jun 7 12:09 Gemfile.lock 6-rw-r--r-- 1 vmb staff 374 Jun 7 12:09 README.md 7-rw-r--r-- 1 vmb staff 227 Jun 7 12:09 Rakefile 8drwxr-xr-x 10 vmb staff 340 Jun 7 12:09 app 9drwxr-xr-x 8 vmb staff 272 Jun 7 12:09 bin 10drwxr-xr-x 14 vmb staff 476 Jun 7 12:09 config 11-rw-r--r-- 1 vmb staff 130 Jun 7 12:09 config.ru 12drwxr-xr-x 3 vmb staff 102 Jun 7 12:09 db 13-rw-r--r-- 1 vmb staff 211 Jun 7 12:06 docker-compose.yml 14-rw-r--r-- 1 vmb staff 184 Jun 7 12:08 entrypoint.sh 15drwxr-xr-x 4 vmb staff 136 Jun 7 12:09 lib 16drwxr-xr-x 3 vmb staff 102 Jun 7 12:09 log 17-rw-r--r-- 1 vmb staff 63 Jun 7 12:09 package.json 18drwxr-xr-x 9 vmb staff 306 Jun 7 12:09 public 19drwxr-xr-x 9 vmb staff 306 Jun 7 12:09 test 20drwxr-xr-x 4 vmb staff 136 Jun 7 12:09 tmp 21drwxr-xr-x 3 vmb staff 102 Jun 7 12:09 vendor

原因

Dockerfile:

dockerfile

1WORKDIR /myapp

docker-compose.yml:

yaml

1 volumes: 2 - .:/myapp

コマンド:

console

1rails new .

追記

フォルダの名前を「myapp」以外にすると、このようなログが出力されます。
myappの部分をすべて任意の名前のフォルダ名に変更したのですが

どこかで書き換えを誤っているものと思われます

すべての箇所を正確に書き換えればファイルは出力されます
以下に myapp をすべて hello-world に書き換えて実行した結果を示します

Dockerfile:

dockerfile

1FROM ruby:2.5 2RUN apt-get update -qq && apt-get install -y nodejs postgresql-client 3RUN mkdir /hello-world 4WORKDIR /hello-world 5COPY Gemfile /hello-world/Gemfile 6COPY Gemfile.lock /hello-world/Gemfile.lock 7RUN bundle install 8COPY . /hello-world 9 10# Add a script to be executed every time the container starts. 11COPY entrypoint.sh /usr/bin/ 12RUN chmod +x /usr/bin/entrypoint.sh 13ENTRYPOINT ["entrypoint.sh"] 14EXPOSE 3000 15 16# Start the main process. 17CMD ["rails", "server", "-b", "0.0.0.0"]

entrypoint.sh:

bash

1#!/bin/bash 2set -e 3 4# Remove a potentially pre-existing server.pid for Rails. 5rm -f /hello-world/tmp/pids/server.pid 6 7# Then exec the container's main process (what's set as CMD in the Dockerfile). 8exec "$@"

docker-compose.yml:

yaml

1version: '3' 2services: 3 db: 4 image: postgres 5 volumes: 6 - ./tmp/db:/var/lib/postgresql/data 7 environment: 8 POSTGRES_PASSWORD: password 9 web: 10 build: . 11 command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" 12 volumes: 13 - .:/hello-world 14 ports: 15 - "3000:3000" 16 depends_on: 17 - db

コマンド:

console

1$ docker-compose run web rails new . --force --no-deps --database=postgresql 2Creating network "test-rails_default" with the default driver 3 4---略--- 5 6Successfully built fe37ff08edcf 7Successfully tagged test-rails_web:latest 8Starting test-rails_db_1 ... done 9 exist 10 create README.md 11 create Rakefile 12 create .ruby-version 13 create config.ru 14 create .gitignore 15 force Gemfile 16 run git init from "." 17Initialized empty Git repository in /hello-world/.git/ 18 create package.json 19 create app 20 create app/assets/config/manifest.js 21 22---略--- 23 24 create tmp/storage 25 create tmp/storage/.keep 26 remove config/initializers/cors.rb 27 remove config/initializers/new_framework_defaults_5_2.rb 28 run bundle install 29The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`. 30Fetching gem metadata from https://rubygems.org/............ 31Fetching gem metadata from https://rubygems.org/. 32Resolving dependencies.... 33Using rake 13.0.1 34 35---略--- 36 37Bundle complete! 18 Gemfile dependencies, 78 gems now installed. 38Use `bundle info [gemname]` to see where a bundled gem is installed. 39Post-install message from chromedriver-helper: 40 41 +--------------------------------------------------------------------+ 42 | | 43 | NOTICE: chromedriver-helper is deprecated after 2019-03-31. | 44 | | 45 | Please update to use the 'webdrivers' gem instead. | 46 | See https://github.com/flavorjones/chromedriver-helper/issues/83 | 47 | | 48 +--------------------------------------------------------------------+ 49 50Post-install message from sass: 51 52Ruby Sass has reached end-of-life and should no longer be used. 53 54* If you use Sass as a command-line tool, we recommend using Dart Sass, the new 55 primary implementation: https://sass-lang.com/install 56 57* If you use Sass as a plug-in for a Ruby web framework, we recommend using the 58 sassc gem: https://github.com/sass/sassc-ruby#readme 59 60* For more details, please refer to the Sass blog: 61 https://sass-lang.com/blog/posts/7828841 62 63 run bundle exec spring binstub --all 64* bin/rake: Spring inserted 65* bin/rails: Spring inserted

ファイルの確認:

console

1$ ls -l 2total 35 3drwxr-xr-x 1 shinoda 197121 0 Jul 4 19:57 app 4drwxr-xr-x 1 shinoda 197121 0 Jul 4 19:58 bin 5drwxr-xr-x 1 shinoda 197121 0 Jul 4 19:57 config 6-rw-r--r-- 1 shinoda 197121 130 Jul 4 19:57 config.ru 7drwxr-xr-x 1 shinoda 197121 0 Jul 4 19:57 db 8-rw-r--r-- 1 shinoda 197121 377 Jul 4 19:56 docker-compose.yml 9-rw-r--r-- 1 shinoda 197121 498 Jul 4 19:55 Dockerfile 10-rwxr-xr-x 1 shinoda 197121 207 Jul 4 19:55 entrypoint.sh 11-rw-r--r-- 1 shinoda 197121 2228 Jul 4 19:57 Gemfile 12-rw-r--r-- 1 shinoda 197121 5324 Jul 4 19:58 Gemfile.lock 13drwxr-xr-x 1 shinoda 197121 0 Jul 4 19:57 lib 14drwxr-xr-x 1 shinoda 197121 0 Jul 4 19:57 log 15-rw-r--r-- 1 shinoda 197121 69 Jul 4 19:57 package.json 16drwxr-xr-x 1 shinoda 197121 0 Jul 4 19:57 public 17-rw-r--r-- 1 shinoda 197121 227 Jul 4 19:57 Rakefile 18-rw-r--r-- 1 shinoda 197121 374 Jul 4 19:57 README.md 19drwxr-xr-x 1 shinoda 197121 0 Jul 4 19:57 storage 20drwxr-xr-x 1 shinoda 197121 0 Jul 4 19:57 test 21drwxr-xr-x 1 shinoda 197121 0 Jul 4 19:57 tmp 22drwxr-xr-x 1 shinoda 197121 0 Jul 4 19:57 vendor

投稿2020/07/03 19:10

編集2020/07/04 11:21
y_shinoda

総合スコア3272

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

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

is02

2020/07/04 02:08 編集

ご回答ありがとうございます。 そのファイルが生成されないです。workdirで書いてるのはmyappフォルダの中にdocker-compose.ymlなどが入っていて、実行すると同じ階層にファイルなどが生成されるイメージなのですが、生成されないので困っております。
y_shinoda

2020/07/04 03:45

質問への追記・修正、ベストアンサー選択の依頼 を投稿しました、 ご確認おねがいします
is02

2020/07/04 12:32

追記ありがとうございました。 同じようにやったら正常に実行されました。 ありがとうございました
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問