有没有办法编译和静态链接Docker的ruby库?

有没有办法编译和静态链接Docker的ruby库?

问题描述:

UPDATED 6 29 2015:

InfraRuby编译器和运行时静态类型的Ruby在JVM上!

我想要一个单独的二进制文件,静态链接,从一个简单的红宝石爬行器建立一个苗条的码头码头容器。

I'd like to have a single binary, statically linked, out of a simple ruby crawler to build a slim docker container.

/ p>

Something like what Go produces with:

CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .

(从为Go应用程序构建最小Docker容器)。

有没有办法用ruby / rails做这个?

Is there a way of doing this with ruby/rails?

为什么要打扰?当您为您的红宝石应用程序创建Docker容器时,您已经创建了一个方便的发行包。

Why bother? When you create a docker container for your ruby app you are already creating a convenient package for distribution.

我建议您查看 ruby​​ rails 官方图片。在容器构建过程中,他们将运行gem bundler来打包依赖关系。

I would suggest checking out the ruby and rails official images. During the container build process they will run the gem bundler in order to package dependencies.

简单的红宝石脚本项目

├── Dockerfile
├── Gemfile
├── Gemfile.lock
└── helloworld.rb

图像是正常建立的

docker build -t my-ruby-app .

并运行如下:

$ docker run --rm my-ruby-app
    __  __     ____                             __    __
   / / / /__  / / /___     _      ______  _____/ /___/ /
  / /_/ / _ \/ / / __ \   | | /| / / __ \/ ___/ / __  / 
 / __  /  __/ / / /_/ /   | |/ |/ / /_/ / /  / / /_/ /  
/_/ /_/\___/_/_/\____/    |__/|__/\____/_/  /_/\__,_/ 



Dockerfile



Dockerfile

FROM ruby:2.1-onbuild
CMD ["ruby", "helloworld.rb"]



helloworld.rb



helloworld.rb

require "artii"

a = Artii::Base.new :font => 'slant'
puts a.asciify('Hello world')



Gemfile



source "https://rubygems.org"

gem "artii"