1

I've looked at 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 Passing environment variables not working with Docker but this concerns passing environment variables through docker run.

Here's my prod.Dockerfile:

FROM ubuntu:20.04

ARG SSH_PRIVATE_KEY

RUN echo "Key is $SSH_PRIVATE_KEY."

and the docker build command:

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

Resulting output:

Key is .

Yet the output of cat ~/.ssh/id_rsa is:

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

What am I missing?

Mario Ishac
  • 5,060
  • 3
  • 21
  • 52

1 Answers1

1

Replace SHH_PRIVATE_KEY with SSH_PRIVATE_KEY.

docker build -f prod.Dockerfile \
   --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" \
   .
Ahmed ElMetwally
  • 2,276
  • 3
  • 10
  • 15