sshpass not executing in bash script sshpass not executing in bash script docker docker

sshpass not executing in bash script


Two possible reason

  • You apk command is wrong, it should be RUN apk add --update bash openssh sshpass, but I assume it typo

  • Seems like the known host entry is missing, you should check logs `docker logs -f , Also need to add entry in for known-host, check the suggested build script below.

Here is a working example that you can try

Dockerfile

FROM alpineRUN apk add --update bash openssh sshpassCOPY build.sh /home/build/build.shCMD ["bin/sh", "/home/build/build.sh"]

build script

#!/bin/bashecho "adding host to known host"mkdir -p ~/.sshtouch ~/.ssh/known_hosts ssh-keyscan sftp >> ~/.ssh/known_hosts echo "run command on remote server"sshpass -p pass sftp foo@sftp  << EOF    ls    pwdEO

Now build the image, docker build -t ssh-pass .

and finally, the docker-compose for testing the above

version: '3'services:  sftp-client:      image: ssh-pass      depends_on:        - sftp  sftp:    image: atmoz/sftp    ports:        - "2222:22"    command: foo:pass:1001

so you will able to connect the sftp container using docker-compose up