我为什么要使用bash -l -c我的容器内? [英] Why do I have to use bash -l -c inside my container?
问题描述
我已经创建使用以下Dockerfile(截)泊坞窗容器:
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 泊坞窗运行[...] RVM
我得到无法找到RVM,但如果我跑泊坞窗运行[...] /斌/ 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的问题 - 我presume有一些关于如何/安装在那里的东西,可能与下运行根安装
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
安装Ruby使用RVM是推荐的方法,但是如果你想运行在非交互式的,非登陆shell的东西(即泊坞窗容器内),这恰恰会导致路径和环境变量和登录太多的麻烦脚本没有运行。
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.
从包装回购( 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,因为我通过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选项present,那么命令将从字符串读取。
-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这样来砸首先读
/ 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
。
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屋!