【发布时间】:2015-12-18 21:33:07
【问题描述】:
我在/root/.profile 中定义了一个bash 函数nvm。 docker build 在RUN 步骤中调用该函数时找不到该函数。
RUN apt-get install -y curl build-essential libssl-dev && \
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh
RUN nvm install 0.12 && \
nvm alias default 0.12 && \
nvm use 0.12
错误是
Step 5 : RUN nvm install 0.12
---> Running in b639c2bf60c0
/bin/sh: nvm: command not found
我设法通过用bash -ic 包装它来调用nvm,这将加载/root/.profile。
RUN bash -ic "nvm install 0.12" && \
bash -ic "nvm alias default 0.12" && \
bash -ic "nvm use 0.12"
上述方法工作正常,但它有一个警告
bash: cannot set terminal process group (1): Inappropriate ioctl for device
bash: no job control in this shell
我想知道是否有一种更简单、更简洁的方法可以直接调用 bash 函数,因为它是没有 bash -ic 包装的普通二进制文件?也许像
RUN load_functions && \
nvm install 0.12 && \
nvm alias default 0.12 && \
nvm use 0.12
【问题讨论】:
-
RUN bash -c 'nvm install 0.12 && nvm alias default 0.12 && nvm use 0.12'应该可以解决问题。对你起作用吗? (我不能 100% 确定,因为我不知道您的容器的详细情况如何) -
它工作正常。但我正在寻找更好的解决方案。
-
好的,检查我的答案。 shell 脚本是最简洁的方法。
-
到目前为止,您还没有接受我的回答。 更好的解决方案是什么意思?
-
NVM 不是为 Docker 设计的。你真的想要两个 Node.js 在一个容器中吗?