docker - Dockerfile变量的if else子句不起作用

标签 docker dockerfile

以下在我的Dockerfile中不起作用:

RUN if $SSH_PRIVATE_KEY -eq ""; then echo "SSH key is not set, aborting"; exit 1; else echo "SSH key is set"; fi

我收到以下错误:
Step 4/15 : RUN if $SSH_PRIVATE_KEY -eq ""; then echo "SSH key is not set, aborting"; exit 1; else echo "SSH key is set"; fi
 ---> Running in 3bd29320f0e3
/bin/sh: -eq: command not found

我想检查$SSH_PRIVATE_KEY变量是否包含任何内容。

最佳答案

在变量周围添加引号(如果变量中可能有空格),只需使用=运算符进行字符串比较即可。

在Bourne shell中,它将是:

if [ "$SSH_PRIVATE_KEY" = "" ]; then echo "SSH key is not set, aborting"; exit 1; else echo "SSH key is set"; fi

关于docker - Dockerfile变量的if else子句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48869814/

相关文章:

docker - 来自守护程序的错误响应:无法启动容器

docker - 使用最新的 Jenkins 创建docker镜像

docker - 在docker中运行两个服务节点和python

docker - 多阶段docker镜像是否具有相同的层?

linux - 连接到 docker 容器上公开的端口时连接被拒绝

node.js - 如何将 NodeJS 与 Angular 连接(在 Nginx 中)

Docker:如何正确清除 Docker 容器的日志?

docker - 使 `pipenv run` 运行多个命令

node.js - EBUSY : resource busy or locked in Docker when trying to do npm install

docker - freeipa-server 容器不会在 docker compose 中启动