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?

1 Answer 1

2

Replace SHH_PRIVATE_KEY with SSH_PRIVATE_KEY.

docker build -f prod.Dockerfile \
   --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" \
   .
Sign up to request clarification or add additional context in comments.

1 Comment

Dang, can't believe I kept correcting SHH to SSH in my head. Thanks a ton.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.