创建 onbuild Dockerfile
只需要加上一行 FROM rails:onbuild
创建的位置为 app 项目的根,Gemfile 的旁边
代码语言:javascript复制[root@h104 blog2]# ls
app bin config config.ru db Gemfile Gemfile.lock lib log public Rakefile README.rdoc test tmp vendor
[root@h104 blog2]# vim Dockerfile
[root@h104 blog2]# cat Dockerfile
FROM rails:onbuild
[root@h104 blog2]#
这个 ONBUILD 镜像可以用于大部分的Rails应用,它会完成类似如下的一些工作 :
- COPY . /usr/src/app
- bundle install
- EXPOSE 3000
- rails server
构建 Rails 容器镜像
注意目录在 app 项目的根一层
代码语言:javascript复制[root@h104 blog2]# ls
app bin config config.ru db Dockerfile Gemfile Gemfile.lock lib log public Rakefile README.rdoc test tmp vendor
[root@h104 blog2]# docker build -t test-rails-app-blog .
Sending build context to Docker daemon 1.104 MB
Step 1 : FROM rails:onbuild
onbuild: Pulling from library/rails
f502f0e93adb: Pull complete
41fb86dd2354: Pull complete
7db4e84aa159: Pull complete
4e4386f0802f: Pull complete
2010da638e26: Pull complete
d63c045b79b9: Pull complete
8471367ded15: Pull complete
2b85b1b3b222: Downloading [================> ] 939.4 kB/2.878 MB
2b85b1b3b222: Pull complete
f9d35d3939ac: Pull complete
1aa074a974f7: Pull complete
097c204ce316: Pull complete
Digest: sha256:e9d8f1a8e16137880b074c60e7c2d6e0ced6bd498d0d871f6c15ffdc619b8e5a
Status: Downloaded newer image for rails:onbuild
# Executing 4 build triggers...
Step 1 : COPY Gemfile /usr/src/app/
Step 1 : COPY Gemfile.lock /usr/src/app/
Step 1 : RUN bundle install
---> Running in a6d3a5d93541
Fetching gem metadata from https://gems.ruby-china.org/...........
Fetching version metadata from https://gems.ruby-china.org/...
Fetching dependency metadata from https://gems.ruby-china.org/..
Installing rake 11.1.2
Installing i18n 0.7.0
Using json 1.8.3
Installing minitest 5.8.4
Installing thread_safe 0.3.5
Installing builder 3.2.2
Installing erubis 2.7.0
Installing mini_portile2 2.0.0
Installing rack 1.6.4
Installing mime-types-data 3.2016.0221
Installing arel 6.0.3
Installing debug_inspector 0.0.2 with native extensions
Installing byebug 8.2.4 with native extensions
Installing coffee-script-source 1.10.0
Installing execjs 2.6.0
Installing thor 0.19.1
Installing concurrent-ruby 1.0.1
Installing multi_json 1.11.2
Using bundler 1.11.2
Installing sass 3.4.22
Installing tilt 2.0.2
Installing spring 1.7.1
Installing sqlite3 1.3.11 with native extensions
Installing rdoc 4.2.2
Installing tzinfo 1.2.2
Installing nokogiri 1.6.7.2 with native extensions
Installing rack-test 0.6.3
Installing mime-types 3.0
Installing binding_of_caller 0.7.2 with native extensions
Installing coffee-script 2.4.1
Installing uglifier 3.0.0
Installing sprockets 3.6.0
Installing sdoc 0.4.1
Installing activesupport 4.2.6
Installing loofah 2.0.3
Installing mail 2.6.4
Installing rails-deprecated_sanitizer 1.0.3
Installing globalid 0.3.6
Installing activemodel 4.2.6
Installing jbuilder 2.4.1
Installing rails-html-sanitizer 1.0.3
Installing rails-dom-testing 1.0.7
Installing activejob 4.2.6
Installing activerecord 4.2.6
Installing actionview 4.2.6
Installing actionpack 4.2.6
Installing actionmailer 4.2.6
Installing railties 4.2.6
Installing sprockets-rails 3.0.4
Installing coffee-rails 4.1.1
Installing jquery-rails 4.1.1
Installing rails 4.2.6
Installing sass-rails 5.0.4
Installing web-console 2.3.0
Installing turbolinks 2.5.3
Bundle complete! 12 Gemfile dependencies, 55 gems now installed.
Bundled gems are installed into /usr/local/bundle.
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:
<= 1.8.6 : unsupported
= 1.8.7 : gem install rdoc-data; rdoc-data --install
= 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!
Step 1 : COPY . /usr/src/app
---> b5b7ed8d740e
Removing intermediate container dee87f8e4f1f
Removing intermediate container 175758fecfc8
Removing intermediate container a6d3a5d93541
Removing intermediate container 8134ef278d71
Successfully built b5b7ed8d740e
[root@h104 blog2]#