1

I made a python code that connects with a SFTP server and reads data. The python script worked well when I ran it on my machine.

For deployment purpose I needed a docker image. So I made one.

However when I run the docker container I get the following Error:

enter image description here

Dockerfile code:

FROM python:3
ADD sftp.py /
ADD config.properties /

RUN pip install pandas pysftp requests configparser

CMD ["python","./sftp.py"]

Python code for connecting to sftp:

cnopts = pysftp.CnOpts(knownhosts=None)
cnopts.hostkeys = None
with pysftp.Connection(host=hostname,username=username,password=password,cnopts=cnopts) as sftp:
    sftp.chdir("Optimove_Output")

I am unable to figure out why it is not working within a docker container. As this code works when run without a container.

Aman Khandelwal
  • 148
  • 1
  • 13
  • if you already know your host then add this in your Dockerfile `mkdir -p /root/.ssh/ && \ touch /root/.ssh/known_hosts && \ ssh-keyscan yourhost.com > ~/.ssh/known_hosts` so you will not need to mount the host directory. – Adiii Oct 11 '19 at 04:52
  • The host can vary...need not be the same everytime. – Aman Khandelwal Oct 11 '19 at 05:00
  • you got solution to your problem?? – ronit Jun 08 '20 at 12:11

1 Answers1

2

that is because in your localhost you have the file ´known_hosts´, try to run your Container so:

docker run -v $HOME/.ssh/known_hosts:/root/.ssh/known_hosts sbtech2
LinPy
  • 16,987
  • 4
  • 43
  • 57