有没有办法编译和静态链接Docker的ruby库? [英] Is there any way to compile and statically link ruby libs for Docker?

查看:123
本文介绍了有没有办法编译和静态链接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"

这篇关于有没有办法编译和静态链接Docker的ruby库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆