Docker容器了解rbenv全局但不了解ruby [英] Docker container knows rbenv global but not ruby
问题描述
运行docker容器时,它知道rbenv全局。但是无论何时,只要它尝试通过 ruby
或哪个红宝石
或哪里是红宝石找到红宝石
我什么也没得到。它还无法识别 rails-api
或 gem
。发生了什么事?
When running my docker container it knows rbenv global. But when ever it try to find ruby via ruby
or which ruby
or whereis ruby
I get nothing. It also doesn't recognize rails-api
or gem
. What is going on?
FROM centos:6.6
RUN yum update -y
RUN yum install git openssl-devel openssh-server sudo openssl readline-devel readline zlib-devel zlib libxml2-devel libxml2 libxslt-devel libxslt nginx tar gcc libaio libaio-devel -y
RUN rpm -Uvh https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-12.5.1-1.el6.x86_64.rpm
RUN sed -i -e "s/Defaults requiretty.*/ #Defaults requiretty/g" /etc/sudoers
RUN mkdir -p /var/run/sshd
RUN useradd -m -u 1000 -G wheel deploy && echo '%wheel ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/wheel
USER deploy
RUN mkdir ~/dev
RUN git clone https://github.com/sstephenson/rbenv.git ~/.rbenv/
RUN git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
ENV PATH ~/.rbenv/bin:$PATH
RUN echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
RUN source ~/.bash_profile
ENV CONFIGURE_OPTS --disable-install-doc
RUN rbenv install 2.2.3
RUN rbenv global 2.2.3
RUN bash -l -c 'gem update --system'
RUN bash -l -c 'gem update'
RUN bash -l -c 'gem install nokogiri -- --use-system-libraries'
RUN bash -l -c 'gem install bundler rails-api --no-rdoc --no-ri'
COPY oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm /tmp/oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
COPY oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm /tmp/oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
COPY oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm /tmp/oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm
RUN sudo rpm -Uvh /tmp/oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
RUN sudo rpm -Uvh /tmp/oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
RUN sudo rpm -Uvh /tmp/oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm
RUN sudo touch /etc/sysconfig/network
RUN NLS_LANG=American_America.UTF8
ENV ORACLE_HOME=/usr/lib/oracle/12.1/client64
ENV LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib
EXPOSE 22
EXPOSE 3000
EXPOSE 5000
推荐答案
此处的问题是每个 RUN
Dockerfile
中的code>语句发生在其自身的环境中。 RUN源〜/ .bash_profile
会将 $ PATH
设置为具有 /root/.rbenv / shims
。但是随后的 RUN
不会设置此环境,因为他们不会获取 .bash_profile
,因为这不是交互式的
The issue at hand here is that every RUN
statement in the Dockerfile
happens in its own environment. The RUN source ~/.bash_profile
will set $PATH
to have /root/.rbenv/shims
in it. But subsequent RUN
will not have this environment set as they won't source .bash_profile
since this isn't an interactive shell.
解决此问题的简单方法是仅添加 ENV路径$ HOME / .rbenv / bin:$ HOME / .rbenv / shims:$ PATH
在 ruby
和 gem
命令之前。实际上,这是 rbenv
初始Shell脚本中所需的唯一内容。
The easy way to solve this is to just add a ENV PATH $HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH
somewhere before the ruby
and gem
commands. This is really the only bit you should need from the rbenv
init shell script.
这篇关于Docker容器了解rbenv全局但不了解ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!