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

huangapple go评论92阅读模式
英文:

/bin/sh: 1: gvm: not found

问题

问题:

我正在尝试创建一个Dockerfile,用于安装所有运行Go所需的组件,安装GVM(Go版本管理),并安装特定的Go版本。

错误:

当我尝试使用以下命令构建容器时:

docker build -t ##### .

我收到以下错误:

> /bin/sh: 1: gvm: not found
>
> 命令 '/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 #####/#####

#安装Golang依赖项
RUN apt-get -y install curl git mercurial make binutils bison gcc build-essential

#安装Golang
RUN ["/bin/bash", "-c", "bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)"]
#这里不存在gvm...为什么?
RUN gvm install go1.4 -B
RUN gvm use go1.4

问题:

为什么GVM似乎没有安装?如何解决这个错误?

英文:

Problem:

I'm attempting to create a Dockerfile that installs all the components to run Go, to install GVM (Go Version Management), and to install specific Go Versions.

Error:

When I try building the container with:

docker build -t ##### .

I get this error:

> /bin/sh: 1: gvm: not found
>
> The command '/bin/sh -c gvm install go1.4 -B' returned a non-zero code: 127

Installed here:

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

What I tried:

It's clearly able to install GVM but unable to use it. Why?
I thought maybe I needed to refresh the .bashrc or the .bash_profile ... but that didn't work, since they don't exist.

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

Question:

Why does GVM not seem to be installed? How do I get rid of the error?

答案1

得分: 3

你的shell是/bin/sh,但是gvm将其初始化放在~/.bashrc中,并期望使用/bin/bash

你需要在非交互式bash shell中使用source命令来运行gvm的初始化脚本:

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
英文:

Your shell is /bin/sh, but gvm puts its initialization in ~/.bashrc, and expects /bin/bash.

You need to source the gvm initialization scripts to run the commands from a non-interactive 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"]

Or even better might be to put the commands you want to execute in a single bash script and add that to the image.

#!/bin/bash
set -e

source /root/.gvm/scripts/gvm
gvm install go1.4
gvm use go1.4

huangapple
  • 本文由 发表于 2017年1月4日 00:00:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/41447459.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定