简体   繁体   English

获取 RVM 路径后,在 Docker 容器内找不到 Gems

[英]Gems are not found inside Docker container After sourcing RVM path

scenario1场景1

So the problem I am facing like after building the docker images.所以我在构建 docker 图像后面临的问题。 If I am going inside the docker container and doing GEM_PATH=$GEM_HOME gem list it is not showing all the gems installed at the time of building the image.如果我进入GEM_PATH=$GEM_HOME gem list容器并执行GEM_PATH=$GEM_HOME gem list它不会显示构建映像时安装的所有 gem。 it is showing only a few gems.它只显示了一些宝石。

scenario2场景2

If I am not sourcing the RVM path inside the Dockerfile.如果我没有在 Dockerfile 中获取 RVM 路径。 Then If I am going inside the docker container and doing GEM_PATH=$GEM_HOME gem list then it is showing all the gems.然后,如果我进入GEM_PATH=$GEM_HOME gem list容器并执行GEM_PATH=$GEM_HOME gem list那么它会显示所有 gem。

Can anyone please explain to me why this is happening and how I should install and source RVM?任何人都可以向我解释为什么会发生这种情况以及我应该如何安装和获取 RVM? So I can see all the gems inside the container.所以我可以看到容器内的所有宝石。 Basically, I want the scenario1 should work.基本上,我希望场景 1 应该可以工作。 Thanks谢谢

Below is my Dockerfile下面是我的 Dockerfile

FROM ruby:2.6.5
RUN apt-get update -qq && apt-get install -y sudo && apt-get install -y build-essential && apt-get install -y apt-utils && apt-get install -y git
RUN gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && \curl -sSL https://get.rvm.io | sudo bash -s stable --ruby && echo 'source /usr/local/rvm/scripts/rvm' >> /etc/bash.bashrc
RUN /bin/bash -l -c 'gem install bundler -v 1.17.3'
RUN /bin/bash -l -c 'gem install rails --version=5.2.4.1'
WORKDIR /app
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle config set path 'vendor/bundle'
COPY Gemfile Gemfile.lock ./
ARG SSH_KEY
# Make ssh dir
RUN mkdir /root/.ssh/
# Copy ssh
RUN echo "$SSH_KEY" > /root/.ssh/id_rsa && \
   chmod 0600 /root/.ssh/id_rsa
RUN touch /root/.ssh/known_hosts
# Add bitbuckets key
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
RUN bundle install
COPY . ./
EXPOSE 80:80
CMD rails s -p 80 -b '0.0.0.0' -e qa

TL;DR : don't use rvm\\rbenv within a container TL;DR :不要在容器内使用 rvm\\rbenv

the whole thing when using containers, is to bundle\\package all the dependencies inside a container.使用容器的整个过程是捆绑\\打包容器内的所有依赖项。 for instance, if you need ruby 2.9 then use a docker image which has ruby 2.9 installed rather than using rvm [rbenv]( https://github.com/rbenv/rbenv ).例如,如果您需要 ruby​​ 2.9,则使用安装了 ruby​​ 2.9 的docker镜像,而不是使用rvm [rbenv]( https://github.com/rbenv/rbenv )。

since you are using bundler , i will advise you to add rails gem to it, and let bundler manage the dependencies.由于您使用的是bundler ,我会建议您向其中添加rails gem,并让 bundler 管理依赖项。

i assume that you care about the directory where rubygems are being installed for caching propose, and i see that you instruct bundler exactly what is the rubygem home directory我假设您关心为缓存提议安装 ruby​​gems 的目录,并且我看到您指示 bundler 确切地说 ruby​​gem 主目录是什么

RUN bundle config set path 'vendor/bundle'

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

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