Dockerfile 环境变量
Dockerfile env variable
我想在 Dockerfile.app 中创建 env 变量,Sentry 将使用它来对我的构建进行版本控制
这是我在该文件中的内容:
ENV REACT_APP_RELEASE_VERSION=$(git rev-parse --short HEAD)-$(date -u '+%Y-%m-%dT%H:%M:%SZ')
它在 bash 中工作正常:
REACT_APP_RELEASE_VERSION=2a06954-2020-07-01T07:41:49Z
但是在管道构建我的项目时,它抛出错误:
Error response from daemon: failed to parse Dockerfile.app: Syntax error - can't find = in "rev-parse". Must be of the form: name=value
有什么想法吗?
您不能在 Dockerfile ENV 中进行变量扩展,因为您可以在 bash 但不能在 Dockerfile ENV 中使用它。
要处理,您可以在主机上执行 git 操作,并在构建期间将普通值传递给 Dockerfile env 或 ARG。
运行时间:
docker run -it --rm -e REACT_APP_RELEASE_VERSION=$(git rev-parse --short HEAD)-$(date -u '+%Y-%m-%dT%H:%M:%SZ') my_image
现在您将能够在您的应用程序中使用 REACT_APP_RELEASE_VERSION
它的值。
构建时间:
docker build --build-args REACT_APP_RELEASE_VERSION=$(git rev-parse --short HEAD)-$(date -u '+%Y-%m-%dT%H:%M:%SZ') -t my_image .
并更新 Dockerfile
ARG REACT_APP_RELEASE_VERSION
REACT_APP_RELEASE_VERSION=${REACT_APP_RELEASE_VERSION}
我想在 Dockerfile.app 中创建 env 变量,Sentry 将使用它来对我的构建进行版本控制
这是我在该文件中的内容:
ENV REACT_APP_RELEASE_VERSION=$(git rev-parse --short HEAD)-$(date -u '+%Y-%m-%dT%H:%M:%SZ')
它在 bash 中工作正常:
REACT_APP_RELEASE_VERSION=2a06954-2020-07-01T07:41:49Z
但是在管道构建我的项目时,它抛出错误:
Error response from daemon: failed to parse Dockerfile.app: Syntax error - can't find = in "rev-parse". Must be of the form: name=value
有什么想法吗?
您不能在 Dockerfile ENV 中进行变量扩展,因为您可以在 bash 但不能在 Dockerfile ENV 中使用它。
要处理,您可以在主机上执行 git 操作,并在构建期间将普通值传递给 Dockerfile env 或 ARG。
运行时间:
docker run -it --rm -e REACT_APP_RELEASE_VERSION=$(git rev-parse --short HEAD)-$(date -u '+%Y-%m-%dT%H:%M:%SZ') my_image
现在您将能够在您的应用程序中使用 REACT_APP_RELEASE_VERSION
它的值。
构建时间:
docker build --build-args REACT_APP_RELEASE_VERSION=$(git rev-parse --short HEAD)-$(date -u '+%Y-%m-%dT%H:%M:%SZ') -t my_image .
并更新 Dockerfile
ARG REACT_APP_RELEASE_VERSION
REACT_APP_RELEASE_VERSION=${REACT_APP_RELEASE_VERSION}