skip to Main Content

How can I suppress the output of the RUN command in a Dockerfile? In the code below, I’m attempting to redirect the SSH_PRIVATE_KEY to a file using the echo command. However, during image building, the Docker logs reveal the SSH PRIVATE KEY, which I’d like to avoid. Is there a way to silence the RUN command in a Dockerfile, or is there another solution to this issue?

RUN echo "${SSH_PRIVATE_KEY}" > /home/$USER/.ssh/id_ed25519

Build log

 => CACHED [app 10/19] RUN echo "-----BEGIN OPENSSH PRIVATE KEY-----0s9               0.0s

2

Answers


  1. You can redirect both standard output and standard error to /dev/null, such as:

    RUN echo "${SSH_PRIVATE_KEY}" > /home/$USER/.ssh/id_ed25519 > /dev/null 2>&1
    
    Login or Signup to reply.
  2. A simple workaround is to have the key in a file instead in the first place.

    COPY privkey /home/$USER/.ssh/id_ed_25519
    

    with privkey obviously in a local file in the directory where you run docker build et al.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search