2

I want to have passwordless ssh within two docker containers. How to add known_hosts entry for that using docker-compose.yml file

I want to implement ansible on docker env. To deploy and run rpm on deployment node, I need passwordless ssh from container1 to container2. For that I have to add known_hosts key of container1 in container2 node. How to do this ???

user2664210
  • 145
  • 2
  • 13

2 Answers2

1

I don't know any solution using docker-compose.yml. The solution I propose implies create a Dockerfile and execute (creating a shellscript as CMD):

ssh-keyscan -t rsa whateverdomain >> ~/.ssh/known_hosts

Maybe you can scan /ect/hosts or pass a variable as ENV.

Alfonso Tienda
  • 3,442
  • 1
  • 19
  • 34
0

try to mount it from host to container. .

--volume local/path/to/known_hosts:/etc/ssh/ssh_known_hosts

in case it didnt work, take a look at some similar case related to ssh key in docker like : this and this

Fendi jatmiko
  • 2,567
  • 1
  • 9
  • 15
  • do you mean **ansible**? take a look at this if it similar case with yours https://github.com/William-Yeh/docker-ansible/issues/14 also check your edited post again, it seems contains typo makes it even harder to understand what you mean . . – Fendi jatmiko Jan 16 '18 at 05:15
  • I have written shell script which contains commands to install and setup sshd service. I am having entrypoint.sh file in base image. so mentioned this : RUN sed -i '2 a /scripts/03_installSsh.sh' /entrypoint.sh into Dockerfile. When docker container starts I found that shell script execution command gets added in entrypoint.sh file. Still its not getting executed. Why this shell script is not getting executed ? – user2664210 Jan 17 '18 at 11:57