gpt4 book ai didi

docker - 设置 PATH 变量并在 Dockerfile 中获取环境

转载 作者:数据小太阳 更新时间:2023-10-29 03:03:31 25 4
gpt4 key购买 nike

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

我也曾尝试从 Dockerfile 中获取 go 的 .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

最佳答案

乍一看不是很清楚,但是PATH 周围的双引号 不是好的unicode 字符。您应该将它们替换为通常的 ",而不是 (Unicode UTF8 代码点 U+201C)

演示:不一样:

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

关于docker - 设置 PATH 变量并在 Dockerfile 中获取环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48889667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com