Docker RUN fails with "returned a non-zero code: 6"
Asked Answered
J

2

12

I have the following in my docker file:

RUN sudo apt-get install sshpass -y
RUN sshpass -p userPassword scp -r user@server:~/data/* ./

But when I try and build my image it fails with:

Exception caught: The command '/bin/sh -c sshpass -p userPassword scp -r user@server:~/data/* ./' returned a non-zero code: 6 -> [Help 1]

However, if I remove these lines, build the image, ssh onto the container and manually run the command from bash it works perfectly.

Can anyone tell me how to get around this?

Janot answered 27/11, 2015 at 16:11 Comment(0)
K
16

The exit code 6 means that "Host public key is unknown. sshpass exits without confirming the new key."

So either you populate before that the ~/.ssh/known_hostswith the fingerprint of the host, or just ignore the check of the host public key by adding the StrictHostKeyChecking=no option to the scp.

The updated line would look like that:

RUN sshpass -p userPassword scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r user@server:~/data/* ./
Kata answered 27/11, 2015 at 16:46 Comment(1)
this answer of mine: unix.stackexchange.com/a/323751/24044 seems related and AFAICT points to the same solution (albeit with a different method).Dullard
C
0

Same error occurred to me, but my command was different.

It was fixed when i upgraded docker to latest version

Charo answered 13/3, 2022 at 18:20 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Strung
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewSyrinx

© 2022 - 2024 — McMap. All rights reserved.