为什么我必须在我的容器内使用bash -l -c? [英] Why do I have to use bash -l -c inside my container?

查看:417
本文介绍了为什么我必须在我的容器内使用bash -l -c?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下Dockerfile(截断)创建了一个docker容器:

I've created a docker container using the following Dockerfile (truncated):

FROM ubuntu:12.04
# curl enables downloading of other things
RUN apt-get install curl -y
# download and install rvm...
RUN \curl -L https://get.rvm.io | bash -s stable
# ... so that we can install ruby
RUN /bin/bash -l -c "rvm requirements"

等等。

这一切都有效,但我遇到的问题是如何/在哪里安装

This all works, but the problem I have is how / where the packages are installed.

如果我只是运行rvm使用 docker运行[...] rvm 我得到无法找到rvm ,但是如果我运行 docker运行[...] / bin / bash -l -crvm它可以工作。 (我在网上找到了-l -c选项,但不知道他们在做什么,找不到我正在做的令人满意的解释!)

If I just run rvm using docker run [...] rvm I get "Unable to locate rvm", but if I run docker run [...] /bin/bash -l -c "rvm" it works. (I found the "-l -c" options online, but have no idea what they do, and can't find a satisfactory explanation of what I'm doing!)

这不是码头问题 - 这是一个bash / * nix问题 - 我假设有一些关于如何/在哪里安装的东西,可能与在根目录下运行安装有关?

This isn't a docker question - it's a bash / *nix question - I presume there's something about how / where things are installed, possibly related to running the install under root?

只需要清楚 - 我希望能够从CLI直接安装的东西。

Just to be clear - I want to be able to run the things that I install direct from the CLI.

编辑1

使用rvm安装Ruby是推荐的方法,但是如果要在非交互式非登录shell(即在Docker容器内)运行东西,则只是导致路径和环境变量和登录脚本不能运行的麻烦太多了。

Installing Ruby using rvm is the recommended method, however if you want to run things in a non-interactive, non-login shell (i.e. within a docker container), this just causes too much hassle with paths and environment variables and login scripts not running.

鉴于我正在使用它来运行一个docker容器,根据定义是隔离的,可恢复(只是建立另一个),我不太在乎切换版本,或隔离包,所以我已经决定从包裹repo( http://brightbox.com/docs/ruby/ubuntu/ )安装Ruby 。这个'只是工作'。

Given that I am using this to run a docker container, which by definition is isolated, and recoverable (just build another one), I don't really care about switching versions, or isolating packages, and so I've decided to install Ruby from a package repo (http://brightbox.com/docs/ruby/ubuntu/) instead. This 'just works'.

它可能不适用于你 - 我只安装Ruby,以获得Foreman gem,因为我通过Procfile运行应用程序所以我不是那么讨厌细节,我只需要它的工作。如果你正在构建一个Ruby应用程序,我不会遵循我的建议。

It may not work for you - I am only installing Ruby in order to get the Foreman gem, as I am running an app through a Procfile, so I'm not that fussed about the details, I just need it to work. If you're building a Ruby app, I wouldn't follow my advice.

我的Dockerfile在这里,FWIW, https://index.docker.io/u/yunojuno/dev/

My Dockerfile is here, FWIW, https://index.docker.io/u/yunojuno/dev/

推荐答案

bash(1)


  • -l <​​/ code>使bash行为好像被调用为登录shell

  • -c 如果存在-c选项,则从字符串读取命令。

  • -l Make bash act as if it had been invoked as a login shell
  • -c If the -c option is present, then commands are read from string.

您正在运行传递给 -c 参数的命令。 -l <​​/ code>使其成为一个登录shell,所以bash首先读取 / etc / profile ,这可能有 rvm 这是什么使它工作。

You're running the command passed to the -c argument. -l makes it a login shell so bash first reads /etc/profile, which probably has the path to rvm which is what makes it work.

FWIW,这里是我要安装的 rvm 在Docker容器中。

FWIW, here's what I do to install rvm in a docker container.

# Install some dependencies
RUN apt-get -y -q install curl rubygems

# Install rvm
RUN curl -L https://get.rvm.io | bash -s stable

# Install package dependencies
RUN /usr/local/rvm/bin/rvm requirements

# Install ruby
RUN /usr/local/rvm/bin/rvm install ruby-2.0.0

# create first wrapper scripts
RUN /usr/local/rvm/bin/rvm wrapper ruby-2.0.0 myapp rake rails gem

这篇关于为什么我必须在我的容器内使用bash -l -c?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆