Ruby是一种高级的、解释型的编程语言,以其清晰的语法和易于理解的代码而闻名

env

  • centos8
  • ruby3.2
  • docker-24.05

安装指导文档

1.download

2.build image

2.1dockerfile

add压缩文件,会自动解压到目标目录。使用分阶段构建,编译后提取成果到最终镜像中

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
FROM centos:centos8.4.2105 AS builder
MAINTAINER [email protected]
WORKDIR /opt/
ADD *.tar.gz /opt/

# replace china yum repos
RUN rm -rf /etc/yum.repos.d/*  \
    && curl -s  -o  /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo \
    && curl -s -o /etc/yum.repos.d/epel-archive-8.repo  https://mirrors.aliyun.com/repo/epel-archive-8.repo \
    && dnf clean all && dnf makecache\
    && dnf install -y gcc gcc-c++ make autoconf zlib-devel  openssl-devel libffi-devel readline-devel \
    && dnf install -y diffutils file

# libyaml
RUN cd yaml-0.1.7/ && ./configure -q --prefix=/usr/local \
    && make -s -j4 && make -s install -j4 \
    && echo "/usr/local/lib" > /etc/ld.so.conf.d/yaml.conf && ldconfig && cd -

# ruby
RUN cd ruby-3.2.5/ \
    && ./configure -q --prefix=/usr/local/ruby \
    && make -s -j4 &&  make install  -s -j4 \
    && echo "/usr/local/ruby/lib" > /etc/ld.so.conf.d/ruby.conf && ldconfig \
    && echo 'export PATH=/usr/local/ruby/bin:$PATH' > /etc/profile.d/ruby.sh \
    && source /etc/profile && ruby -v && gem -v \
    && gem sources --remove https://rubygems.org/ \
    && gem sources -a https://mirrors.aliyun.com/rubygems/ && cd -

# clean
RUN rm -rf /opt/* &&  dnf clean all

FROM  centos:centos8.4.2105
#COPY --from=builder /usr/local/{lib,include,ruby} /usr/local/
COPY --from=builder /usr/local/ /usr/local/
RUN echo "/usr/local/lib" > /etc/ld.so.conf.d/yaml.conf && echo "/usr/local/ruby/lib" > /etc/ld.so.conf.d/ruby.conf \
        && ldconfig && echo 'export PATH=/usr/local/ruby/bin:$PATH' > /etc/profile.d/ruby.sh \
        && source /etc/profile && ruby -v && gem -v \
        && gem sources --remove https://rubygems.org/ \
        && gem sources -a https://mirrors.aliyun.com/rubygems/

2.2构建文件清单及构建过程

├── Dockerfile
├── ruby-3.2.5.tar.gz
└── yaml-0.1.7.tar.gz


docker build -t centos8:ruby-3.2  .
....
installing bundled gem cache:       /usr/local/ruby/lib/ruby/gems/3.2.0/cache
ruby 3.2.5 (2024-07-26 revision 31d0f1a2e7) [x86_64-linux]
3.4.19
https://rubygems.org/ removed from sources
https://mirrors.aliyun.com/rubygems/ added to sources
/opt
Removing intermediate container 785198bbb495
 ---> f6aa2b129d31
Step 8/11 : RUN rm -rf /opt/* &&  dnf clean all
 ---> Running in e0113a5ed921
28 files removed
Removing intermediate container e0113a5ed921
 ---> 1d0de61023c1
Step 9/11 : FROM  centos:centos8.4.2105
 ---> 5d0da3dc9764
Step 10/11 : COPY --from=builder /usr/local/ /usr/local/
 ---> 278d47620c20
Step 11/11 : RUN echo "/usr/local/lib" > /etc/ld.so.conf.d/yaml.conf && echo "/usr/local/ruby/lib" > /etc/ld.so.conf.d/ruby.conf         && ldconfig && echo 'export PATH=/usr/local/ruby/bin:$PATH' > /etc/profile.d/ruby.sh         && source /etc/profile && ruby -v && gem -v         && gem sources --remove https://rubygems.org/         && gem sources -a https://mirrors.aliyun.com/rubygems/
 ---> Running in 16fe508c8904
ruby 3.2.5 (2024-07-26 revision 31d0f1a2e7) [x86_64-linux]
3.4.19
https://rubygems.org/ removed from sources
https://mirrors.aliyun.com/rubygems/ added to sources
Removing intermediate container 16fe508c8904
 ---> 97a8a6648dbf
Successfully built 97a8a6648dbf
Successfully tagged centos8:ruby-3.2
[root@centos8-51 centos8-ruby]# docker  images
REPOSITORY               TAG              IMAGE ID       CREATED          SIZE
centos8                  ruby-3.2         97a8a6648dbf   11 minutes ago   464MB

3.测试安装

docker run --rm -it centos8:ruby-3.2  bash

# 安装fpm
gem install fpm

# 查看fpm版本
[root@b7a190dd24b7 /]# 
[root@b7a190dd24b7 /]# fpm --version
1.15.1