Docker Compose Rails教程:文件在哪里?

时间:2015-06-23 07:59:25

标签: ruby-on-rails docker

我一直关注Docker Compose Rails tutorial。它一直很好,直到我运行docker-compose run web rails new . --force --database=postgresql --skip-bundle(好吧,安装很顺利:))

以下是发生的事情:

▶ sudo docker-compose run web rails new . --force --database=postgresql --skip-bundle
Creating dockers_db_1...
Building web...
Step 0 : FROM ruby:2.1.4
 ---> 766162a99b23
Step 1 : RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
 ---> Using cache
 ---> 0053b73703c1
Step 2 : RUN mkdir /myapp
 ---> Using cache
 ---> bf768c1e06ca
Step 3 : WORKDIR /myapp
 ---> Using cache
 ---> 934af3ef8124
Step 4 : ADD Gemfile /myapp/Gemfile
 ---> Using cache
 ---> 3666057e0d52
Step 5 : RUN bundle install
 ---> Using cache
 ---> e796e93e83d6
Step 6 : ADD . /myapp
 ---> Using cache
 ---> 03249ac42a63
Successfully built 03249ac42a63
       exist  
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
       force  Gemfile
      create  app
      create  app/assets/images/rails.png
      create  app/assets/javascripts/application.js
      create  app/assets/stylesheets/application.css
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/mailers
      create  app/models
      create  app/views/layouts/application.html.erb
      create  app/mailers/.gitkeep
      create  app/models/.gitkeep
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/secret_token.rb
      create  config/initializers/session_store.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  lib/assets
      create  lib/assets/.gitkeep
      create  log
      create  log/.gitkeep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/index.html
      create  public/robots.txt
      create  script
      create  script/rails
      create  test/fixtures
      create  test/fixtures/.gitkeep
      create  test/functional
      create  test/functional/.gitkeep
      create  test/integration
      create  test/integration/.gitkeep
      create  test/unit
      create  test/unit/.gitkeep
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.gitkeep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.gitkeep
      create  vendor/plugins
      create  vendor/plugins/.gitkeep

所以我喜欢“哦,很酷,它有效”。

但是我需要编辑Gemfile。主机Gemfile未更改:

cat Gemfile 
source 'https://rubygems.org'
gem 'rails', '3.2.18'

所以我想我需要进入我的码头工人:

▶ sudo docker images                         
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
workspace_web       latest              03249ac42a63        8 hours ago         835.3 MB
dockers_web         latest              03249ac42a63        8 hours ago         835.3 MB
postgres            latest              7bf0ec35adaf        6 days ago          214 MB
hello-world         latest              91c95931e552        9 weeks ago         910 B
ruby                2.1.4               766162a99b23        7 months ago        798.3 MB

但文件看起来一样:

▶ sudo docker run -t -i workspace_web /bin/bash
root@400ca3fd62a7:/myapp# cat Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.18'

rails new生成的文件在哪里?一直在寻找,但没有成功。

我在使用Debian,所以不使用Boot2docker。

由于

2 个答案:

答案 0 :(得分:1)

docker-rails是我刚创建的一个项目,用于使用docker(和CI)轻松实现。我认为它可以帮助您减少在docker上启动和运行rails所需的配置量。

它还可以帮助您任何这些文件提取回主机。在我的性能测试中,做了类似的事情:

body {
    overflow: hidden;
    margin: 0 10px;
}
.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}
.lower {
    flex: 1;
    overflow-y: scroll;
    border: 1px dotted red;
    margin-bottom: 10px;
}

最多 4x ,因为它在主机上安装了卷body { overflow: hidden; margin: 0 10px; } .container { display: flex; flex-direction: column; height: 100vh; } .lower { flex: 1; overflow-y: scroll; border: 1px dotted red; margin-bottom: 10px; }。相反,正如在docker-rails的示例中所做的那样,使用<div class="container"> <div class="upper"> <p>hello world</p> <p>hello again</p> </div> <div class="lower"> <ul> <li>hello world 1</li> <li>hello world 2</li> <li>hello world 3</li> <li>hello world 4</li> <li>hello world 5</li> <li>hello world 6</li> <li>hello world 7</li> <li>hello world 8</li> <li>hello world 9</li> <li>hello world 10</li> <li>hello world 11</li> <li>hello world 12</li> <li>hello world 13</li> <li>hello world 14</li> <li>hello world 15</li> <li>hello world 16</li> <li>hello world 17</li> <li>hello world 18</li> <li>hello world 19</li> <li>hello world 20</li> <li>hello world 21</li> <li>hello world 22</li> <li>hello world 23</li> <li>hello world 24</li> <li>hello world 25</li> <li>hello world 26</li> <li>hello world 27</li> <li>hello world 28</li> <li>hello world 29</li> <li>hello world 30</li> </ul> </div> </div> volumes: - .:/myapp 来获得几乎本机I / O速度(绕过任何联合文件系统)和.作为项目目录。这意味着您的所有文件都将驻留在容器中,因此您需要Dockerfile任何想要的文件。 VOLUME使这非常简单,例如,我将这个提取用于我的测试工件:

COPY

TLDR; 有很多技巧让docker / compose正确运行rails。结帐docker-rails,它将所有这些都放在一个地方。

答案 1 :(得分:0)

docker-compose.yml中的

注意到以下几行:

volumes:
- .:/myapp

/myapp已映射到您在运行docker-compose run时所处的当前目录 - 这样您应该在哪里查找文件。

当您sudo docker run -t -i workspace_web /bin/bash时,您没有添加-v .:/mapp,因此您的/myapp文件夹中没有安装文件,并且容器内仍为空卷。