0

我正在处理一个 docker 文件以在Codenvy上创建一个自定义工作区。当我创建工作区时,一切似乎都安装正确,但是当工作区打开并输入时,ruby -v我得到:

bash: ruby: command not found

导轨也一样:

user@de98ec223612:/projects$ rails -v
bash: rails: command not found

如果我输入 rvm list 我得到

user@de98ec223612:/projects$ rvm info

ruby-2.4.0:

  system:
    uname:        "Linux de98ec223612 3.10.0-514.10.2.el7.x86_64 #1 SMP Fri Mar 3 00:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux"
    name:         "Ubuntu"
    version:      "16.04"
    architecture: "x86_64"
    bash:         "/bin/bash => GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)"
    zsh:          " => not installed"
    remote path:  "ubuntu/16.04/x86_64"

  rvm:
    version:      "rvm 1.29.1 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io/]"
    updated:      "5 minutes 31 seconds ago"
    path:         "/home/user/.rvm"
    autolibs:     "[4] Allow RVM to use package manager if found, install missing dependencies, install package manager (only OS X)."

  ruby:
    interpreter:  "ruby"
    version:      "2.4.0p0"
    date:         "2016-12-24"
    platform:     "x86_64-linux"
    patchlevel:   "2016-12-24 revision 57164"
    full_version: "ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]"

  homes:
    gem:          "/home/user/.rvm/gems/ruby-2.4.0"
    ruby:         "/home/user/.rvm/rubies/ruby-2.4.0"

binaries:
    ruby:         "/home/user/.rvm/rubies/ruby-2.4.0/bin/ruby"
    irb:          "/home/user/.rvm/rubies/ruby-2.4.0/bin/irb"
    gem:          "/home/user/.rvm/rubies/ruby-2.4.0/bin/gem"
    rake:         "/home/user/.rvm/rubies/ruby-2.4.0/bin/rake"

  environment:
    PATH:         "/home/user/.rvm/gems/ruby-2.4.0/bin:/home/user/.rvm/gems/ruby-2.4.0@global/bin:/home/user/.rvm/rubies/ruby-2.4.0/bin:/usr/lib/jvm/java-1.8.0-open
jdk-amd64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bundle/bin:/usr/lib/postgresql/9.6/bin:/home/user/.rvm/bin"
    GEM_HOME:     "/home/user/.rvm/gems/ruby-2.4.0"
    GEM_PATH:     "/home/user/.rvm/gems/ruby-2.4.0:/home/user/.rvm/gems/ruby-2.4.0@global"
    MY_RUBY_HOME: "/home/user/.rvm/rubies/ruby-2.4.0"
    IRBRC:        "/home/user/.rvm/rubies/ruby-2.4.0/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

在我看来,东西安装正确。

如果我键入/home/user/.rvm/rubies/ruby-2.4.0/bin/ruby -v它会显示正确的 ruby​​ 版本。 /home/user/.rvm/rubies/ruby-2.4.0/bin在 PATH 为什么不被搜索?

如果有帮助,这是我的 docker 文件的相关部分。

# Install RVM
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB &&\
    echo progress-bar >> ~/.curlrc &&\
    \curl -sSL https://get.rvm.io | bash -s stable &&\
    /bin/bash -l -c 'source ~/.rvm/scripts/rvm'

# Install Ruby
RUN /bin/bash -l -c 'rvm requirements' &&\
    /bin/bash -l -c 'rvm install ${RUBY_VERSION}' &&\
    /bin/bash -l -c 'rvm use ${RUBY_VERSION} --default' &&\
    /bin/bash -l -c 'rvm rubygems current'

# Install bundler
RUN /bin/bash -l -c 'gem install bundler'

# Install Rails
RUN /bin/bash -l -c 'gem install rails'

RUN echo $PATH

EXPOSE 3000
WORKDIR /projects    

CMD /bin/bash -l -c 'source ~/.rvm/scripts/rvm' && sudo service postgresql start && tail -f /dev/null

我怎样才能让这些命令在不使用的情况下运行/home/user/.rvm/rubies/ruby-2.4.0/bin

4

2 回答 2

0

我遇到了同样的问题,最终我通过上传以结尾的 /root/.bashrc 文件来修复它

source /opt/rvm/scripts/rvm
source /etc/profile.d/ruby.sh

export PATH=$PATH:/opt/rvm/bin

带有源代码的行是我添加的。导出是由 RVM 在安装时添加的。我的 bashrc 文件的其余部分是 Debian 安装的内容。我刚刚添加了这些行。

我的 ruby​​.sh 文件包含

#!/bin/sh
export RUBY_HOME=/opt/rvm/rubies/default

对我来说,这就是诀窍。当我使用 /bin/bash (非 shell)或通过 /bin/bash -l -c "command going here" 登录时,我的命令 rvm 和 ruby​​ 都会响应。另外,我的 RUBY_HOME 和 GEM_PATH, ... 都被填满了。

我当前的 ruby​​ docker 安装可以在这里找到: https ://github.com/vindevoy/dockerhub-debian-ruby (来源) https://hub.docker.com/r/vindevoy/debian-ruby/(图片)

于 2017-07-19T06:41:10.353 回答
0

如果您的团队可以接受,那么从 Eclipse Che 为 RoR 提供的基本 dockerfile 开始可能会更容易:https ://github.com/eclipse/che-dockerfiles/blob/master/recipes/ruby_rails/Dockerfile

这应该让您了解基础知识,并且社区会保持最新状态。然后,您可以使用您需要的任何其他工具、库、部门来扩展它。

于 2017-06-21T18:00:25.510 回答