/ bin / sh:1:gvm:找不到

问题:

我试图创build一个Dockerfile来安装运行Go的所有组件,安装GVM(Go版本pipe理) ,并安装特定的Go版本。

错误:

当我尝试用以下方法构build容器时:

docker build -t ##### . 

我得到这个错误:

/ bin / sh:1:gvm:找不到

命令“/ bin / sh -c gvm install go1.4-B”返回一个非零的代码:127

安装在这里:

 /root/.gvm/scripts/env/gvm /root/.gvm/scripts/gvm /root/.gvm/bin/gvm 

我试过的:

它显然能够安装GVM,但无法使用它。 为什么? 我想也许我需要刷新.bashrc.bash_profile …但没有奏效,因为它们不存在。

Dockerfile:

 FROM #####/##### #Installing Golang dependencies RUN apt-get -y install curl git mercurial make binutils bison gcc build-essential #Installing Golang RUN ["/bin/bash", "-c", "bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)"] #gvm does not exist here... why? RUN gvm install go1.4 -B RUN gvm use go1.4 

题:

为什么似乎没有安装GVM? 我如何摆脱错误?

你的shell是/bin/sh ,但是gvm把它的初始化放在~/.bashrc ,并且期望/bin/bash

您需要获取gvm初始化脚本以从非交互式bash shell运行命令:

 RUN ["/bin/bash", "-c", ". /root/.gvm/scripts/gvm && gvm install go1.4 -B"] RUN ["/bin/bash", "-c", ". /root/.gvm/scripts/gvm && gvm use go1.4"] 

或者甚至更好的可能是把你想要执行的命令放在一个bash脚本中,并将其添加到图像中。

 #!/bin/bash set -e source /root/.gvm/scripts/gvm gvm install go1.4 gvm use go1.4