Unable to ssh from docker container to another server with port 22

Hello,

I have created a small docker container with ubuntu 16.04.
Creates ssh key and put the public key on another server.
Now trying to ssh to server from docker container, getting an error as permission denied.

Can you give some more information about this:

  • What is your ssh command that you execute in the docker container?
  • On the server, did you placed the content of the public key in the .ssh/authorized_keys file? Did the file already exists? Or is it a new one. Is it a new one, does the file have the proper rights?
  • Does the user you use exists on the servers?

and more important is the sshd started. Docker by default is designed to execute one process only. So all your background services from your ubuntu like sshd, cron, … are usually not running in your ubuntu docker container. You need to explicitly start them.

Also not sure if ssh is the proper thing to do. Cannot you use volumes or something else instead?

Hello Werner,
Thanks for your reply.
I have updated the ssh public key on the server.
With the same key, i am able to checkout the git code from the server through my local system.
But in docker container, while checkout it is asking for a password.
Then I tried with the IP address it is working fine.
But with the domain name, it is not working.
Below command, i am using for checkout.

Why want you to do this in the docker container? Why not wat @think has suggested by using volumes?

On your local system the git clone works, if you use that directory as a volume mount to your container then all data is available to your container.

Hello Werner,

Thanks for your suggestion.
But I want this code on the server, where a user is not going to have access.
And Only I wanted to update the code so it will reflect directly on the server.