Docker 构建无法识别作为 `build-arg` 传递的环境变量

Docker build not recognizing environment variable passed as `build-arg`

我查看了 Can we pass ENV variables through cmd line while building a docker image through dockerfile? which shows me how to pass an environment variable with docker build. After seeing that the environment variable wasn't being defined, I looked at ,但这涉及通过 docker run 传递环境变量。

这是我的 prod.Dockerfile:

FROM ubuntu:20.04

ARG SSH_PRIVATE_KEY

RUN echo "Key is $SSH_PRIVATE_KEY."

docker build命令:

docker build -f prod.Dockerfile \
             --build-arg SHH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" \
             .

结果输出:

Key is .

然而 cat ~/.ssh/id_rsa 的输出是:

-----BEGIN OPENSSH PRIVATE KEY-----
...
-----END OPENSSH PRIVATE KEY-----

我错过了什么?

SHH_PRIVATE_KEY替换为SSH_PRIVATE_KEY

docker build -f prod.Dockerfile \
   --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" \
   .