简体   繁体   English

在docker ubuntu / debian上安装rbenv

[英]Installing rbenv on docker ubuntu/debian

I want to install rbenv on Docker which seems to work but I can't reload the shell. 我想在似乎可以工作的Docker上安装rbenv,但无法重新加载Shell。

FROM node:0.10.32-slim

RUN \
      apt-get update \
  &&  apt-get install -y sudo

RUN \
      echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
  &&  groupadd r \
  &&  useradd r -m -g r -g sudo

USER r

RUN \
      git clone https://github.com/sstephenson/rbenv.git ~/.rbenv \
  &&  echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc \
  &&  echo 'eval "$(rbenv init -)"' >> ~/.bashrc

RUN rbenv # check if it works...

When I run this I get: 当我运行它时,我得到:

docker build .       

..

Step 5 : RUN rbenv
/bin/sh: 1: rbenv: not found

From what I understand, I need to reload the current shell so I can install ruby versions. 据我了解,我需要重新加载当前的shell,以便可以安装ruby版本。 Not sure if I am on the right track. 不知道我是否走对了。

Also see: Using rbenv with Docker 另请参阅: 将rbenv与Docker一起使用

The RUN command executes everything under /bin/sh, thus your bashrc is not evaled at any point. RUN命令执行/ bin / sh下的所有内容,因此您的bashrc在任何时候都不会被逃避。

use this 用这个

&& export PATH="$HOME/.rbenv/bin:$PATH" \

which would append rbenv to /bin/sh's PATH. 它将把rbenv附加到/ bin / sh的PATH中。

Full Dockerfile 完整的Dockerfile

FROM node:0.10.32-slim

RUN \
      apt-get update \
  &&  apt-get install -y sudo

RUN \
      echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
  &&  groupadd r \
  &&  useradd r -m -g r -g sudo

USER r

RUN \
      git clone https://github.com/sstephenson/rbenv.git ~/.rbenv \
  &&  echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc \
  &&  echo 'eval "$(rbenv init -)"' >> ~/.bashrc \
  &&  export PATH="$HOME/.rbenv/bin:$PATH"

RUN rbenv # check if it works...

I'm not sure how Docker works, but it seems like maybe you're missing a step where you source ~/.bashrc , which is preventing you from having the rbenv executable in your PATH . 我不确定Docker的工作方式,但似乎您似乎缺少source ~/.bashrc ,这阻止了您在PATH中使用rbenv可执行文件。 Try adding that right before your first attempt to run rbenv and see if it helps. 在您第一次尝试运行rbenv之前,尝试添加该rbenv ,看看是否有帮助。

You can always solve PATH issues by using the absolute path, too. 您也可以始终使用绝对路径来解决PATH问题。 Instead of just rbenv , try running $HOME/.rbenv/bin/rbenv . 而不是仅仅rbenv ,尝试运行$HOME/.rbenv/bin/rbenv

If that works, it indicates that rbenv has installed successfully, and that your PATH is not correctly set to include its bin directory. 如果可行,则表明rbenv已成功安装,并且您的PATH未正确设置为包括其bin目录。

It looks from reading the other question you posted that docker allows you to set your PATH via an ENV PATH command, like this, for example: 从阅读您发布的另一个问题可以看出,泊坞窗允许您通过ENV PATH命令设置PATH ,例如:

ENV PATH $HOME/.rbenv/bin:/usr/bin:/bin

but you should make sure that you include all of the various paths you will need. 但您应确保包含所需的所有各种路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM