构建Dockerfile时RUN不执行命令

我有一个基于Fedora 31的Dockerfile,我想在其中使用rvm

安装Ruby。

Dockerfile:

FROM fedora:31

ENV RUBY_VERSION 2.6.5
ENV JAVA_VERSION 1.8.0

RUN dnf -y update

RUN dnf -y install gcc-c++ patch readline \
    readline-devel zlib zlib-devel \
    libyaml-devel libffi-devel which procps \
    make bzip2 autoconf automake openssl-devel \
    sqlite-devel procps bison libtool \
    java-${JAVA_VERSION}-openjdk-devel

RUN export PATH=$PATH:/usr/local/rvm/scripts \
  && export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac))))) \
  && curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - \
  && curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import - \
  && curl -L get.rvm.io | bash -s stable \
  && source /etc/profile.d/rvm.sh \
  # RVM Commands below are not executed.
  && rvm reload \
  && rvm install ${RUBY_VERSION} \
  && rvm use ${RUBY_VERSION} --default \
  && export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac))))) \
  && java -version \
  # Error thrown: ruby not found 
  && ruby --version

如上面的Dockerfile中所示,rvm命令都不起作用,因为在构建过程完成时会引发一条命令,指出找不到Ruby。这是出乎意料的,可以预料的是会打印出Ruby版本。

日志:

$ docker build -t java-ruby -f java-ruby.dockerfile .
Sending build context to Docker daemon   5.12kB
Step 1/6 : FROM fedora:31
 ---> f0858ad3febd
Step 2/6 : ENV RUBY_VERSION 2.6.5
 ---> Using cache
 ---> 630b2bc810ab
Step 3/6 : ENV JAVA_VERSION 1.8.0
 ---> Using cache
 ---> d1244ebcaf6c
Step 4/6 : RUN dnf -y update
 ---> Using cache
 ---> b9b12badfb99
Step 5/6 : RUN dnf -y install gcc-c++ patch readline     readline-devel zlib zlib-devel     libyaml-devel libffi-devel which procps     make bzip2 autoconf automake openssl-devel     sqlite-devel procps bison libtool     java-${JAVA_VERSION}-openjdk-devel
 ---> Using cache
 ---> 571b7515ba4c
Step 6/6 : RUN export PATH=$PATH:/usr/local/rvm/scripts   && export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac)))))   && curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -   && curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -   && curl -L get.rvm.io | bash -s stable   && source /etc/profile.d/rvm.sh   && rvm reload   && rvm install ${RUBY_VERSION}   && rvm use ${RUBY_VERSION} --default   && export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac)))))   && java -version   && ruby --version
 ---> Running in 43f2b7dd661f
gpg: directory '/root/.gnupg' created
gpg: keybox '/root/.gnupg/pubring.kbx' created
gpg: key 3804BB82D39DC0E3: 47 signatures not checked due to missing keys
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key 3804BB82D39DC0E3: public key "xxx (RVM signing) <xxx@xxx.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1
gpg: no ultimately trusted keys found
gpg: key 105BD0E739499BDB: public key "xxx <xxx@xxx.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   194  100   194    0     0    160      0  0:00:01  0:00:01 --:--:--   160
100 24535  100 24535    0     0  13495      0  0:00:01  0:00:01 --:--:-- 13495
Downloading https://github.com/rvm/rvm/archive/1.29.9.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc
gpg: Signature made Wed Jul 10 08:31:02 2019 UTC
gpg:                using RSA key 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: Good signature from "xxx <xxx@xxx.com>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7D2B AF1C F37B 13E2 069D  6956 105B D0E7 3949 9BDB
GPG verified '/usr/local/rvm/archives/rvm-1.29.9.tgz'
Creating group 'rvm'
Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,and logout - login again,anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.

  * To start using RVM you need to run `source /etc/profile.d/rvm.sh`
    in all your open shell windows,in rare cases you need to reopen all shell windows.
  * Please do NOT forget to add your users to the <code>rvm</code> group.
     The installer no longer auto-adds root or users to the rvm group. Admins must do this.
     Also,please note that group memberships are ONLY evaluated at login time.
     This means that users must log out then back in before group membership takes effect!
<warn>Thanks for installing RVM ?</warn>
Please consider donating to our open collective to help us maintain RVM.

?  Donate: <code>https://opencollective.com/rvm/donate</code>


openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09,mixed mode)
/bin/sh: ruby: command not found
The command '/bin/sh -c export PATH=$PATH:/usr/local/rvm/scripts   && export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac)))))   && curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -   && curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -   && curl -L get.rvm.io | bash -s stable   && source /etc/profile.d/rvm.sh   && rvm reload   && rvm install ${RUBY_VERSION}   && rvm use ${RUBY_VERSION} --default   && export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac)))))   && java -version   && ruby --version' returned a non-zero code: 127

我运行了一个容器并手动执行了rvm命令,它们按预期方式工作。

日志:

[root@f78cece3dc0a /]# rvm reload \
>   && rvm install ${RUBY_VERSION} \
>   && rvm use ${RUBY_VERSION} --default
RVM reloaded!
Searching for binary rubies,this might take some time.
No binary rubies available for: fedora/31/x86_64/ruby-2.6.5.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for fedora.
Requirements installation successful.
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.6.5,this may take a while depending on your cpu(s)...
ruby-2.6.5 - #downloading ruby-2.6.5,this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13.4M  100 13.4M    0     0  5189k      0  0:00:02  0:00:02 --:--:-- 5189k
No checksum for downloaded archive,recording checksum in user configuration.
ruby-2.6.5 - #extracting ruby-2.6.5 to /usr/local/rvm/src/ruby-2.6.5.....
ruby-2.6.5 - #configuring...............................................
.
.
.
pipippip 回答:构建Dockerfile时RUN不执行命令

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3143607.html

大家都在问