Ssh-agent use in Dockerfile breaks subsequent commands during build

I have used the same Dockerfile that you shared and it worked perfectly for me.
For me it seems like you had a non-printable character in the Dockerfile which caused problem only when it was the last before the next RUN instruction. Since the error message was “invalid argument” and it started with “failed to sovle” which is what Docker throws when it can’t find a file (sometimes the Dockerfile) it is not likely to be caused by a file inside a container.

Try to change this instruction

RUN ssh-agent sh -c 'uname -a' && \
    uname -a && \
    rm -rf /tmp/ssh-*

to this

RUN ssh-agent sh -c 'uname -a' && \
    uname -a && \
    whoami

Since the container is not “booting” and only one process starts in each build layer without the processess that ran in previous layers, ssh agent could hardly cause the issue unless there is something going on that I have never heard of, which wouldn’t be a miracle and I almost hope it is the case so I could learn something new. However, if ssh agent was the reason, I think I should have get the same error.