设置PATH变量并在Dockerfile中获取env

时间:2018-02-20 16:18:36

标签: docker go path dockerfile

我编写了一个Dockerfile来创建安装了Golang的容器。我有一个运行 go version 命令的高斯测试,但是测试失败了,因为路径变量(在Dockerfile中) - 由于某种原因 - 没有保持设置。

我也尝试从Dockerfile内部获取.env,但这似乎也不起作用。

Dockerfile

ENV GIMME_VERSION "v1.4.0"
ENV GO_VERSION "1.4"
ENV JENKINS_HOME "/opt/jenkins"
ENV PATH="~/bin:${PATH}"
ENV PATH=“/opt/jenkins/.gimme/versions/go1.4.linux.amd64/bin:${PATH}“
ENV GOROOT="/opt/jenkins/.gimme/versions/go${GO_VERSION}.linux.amd64"

USER root

RUN yum -y install git && \
    yum -y clean all && \
    rm -rf /var/cache/yum

WORKDIR $JENKINS_HOME

USER jenkins

RUN mkdir ~/bin && \
    curl -sL -o ~/bin/gimme https://raw.githubusercontent.com/travis-
    ci/gimme/${GIMME_VERSION}/gimme && \
    chmod +x ~/bin/gimme && \
    gimme ${GO_VERSION}

USER root

RUN source /opt/jenkins/.gimme/envs/go${GO_VERSION}.linux.amd64.env

Goss Yaml

file:
  /opt/jenkins/.gimme:
    exists: true
    filetype: directory
  /opt/jenkins/.gimme/envs/go1.4.env:
    exists: true
    filetype: file
  /opt/jenkins/.gimme/versions/go1.4.linux.amd64:
    exists: true
    filetype: directory
  /opt/jenkins/.gimme/versions/go1.4.linux.amd64/bin/go:
    exists: true
    filetype: file
  /opt/jenkins/.gimme/versions/go1.4.linux.amd64/pkg:
    exists: true
    filetype: directory
  /opt/jenkins/.gimme/versions/go1.4.linux.amd64/src:
    exists: true
    filetype: directory
  /opt/jenkins/bin/gimme:
    filetype: file
    exists: true
    mode: '0755'
command:
  'gimme version':
  exit-status: 0
  'go version':
  exit-status: 0

1 个答案:

答案 0 :(得分:2)

乍一看并不是很清楚,但PATH周围的双引号并不是一个好的unicode角色。您应该使用通常的"替换它们,而不是(Unicode UTF8代码点U+201C

演示:不一样:

$ od -c <<< \"
0000000   "  \n
0000002
$ od -c <<< \“
0000000 342 200 234  \n
0000004