1

问题:

我正在尝试创建一个 Dockerfile 来安装所有组件以运行 Go、安装GVM (Go Version Management)并安装特定的 Go 版本。

错误:

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

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 但无法使用它。为什么?我想也许我需要刷新.bashrcor the .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 似乎没有安装?如何摆脱错误?

4

1 回答 1

3

您的 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
于 2017-01-03T16:40:30.433 回答