SSH to a docker container from another container on another host

I have a docker container running on an EC2 host and the other on a different ec2 host. How to make ssh from one to another without providing port numbers? I want to do something like ssh root @ ip-address-of-container

+9
docker ssh amazon-web-services
source share
3 answers
0
source share

In order for you to ssh into the second container on port 22, you would need to get the host daemon ec2 vm ssh.

  • One way is to change the ssh port of the host machine by adding the entry in the / etc / ssh / sshd _config file to about 3022. Now you can use -p 22:22 when you start your docker container (s) and you can ssh between them . However, the ssh`ing instance of ec2 is at 3022.

  • If you want host-vms to also have ssh enabled on port 22, then you will need to create a second virtual ethernet interface. This is easy to do if you can set static IPs. something like ifconfig eth0:0 192.168.1.11 up . However, in ec2 this will not be possible since you have DHCP based IP addresses.

  • The third way is to configure your .ssh / config file to map to a non-standard port. This does not allow you to send ssh over port 22, but at least you do not need to know about the non-standard port. Here is a tutorial , and related parts below.

     # contents of $HOME/.ssh/config Host other_docker HostName ec2-host-name-of-other-docker.com Port 22000 User some_user # must be added to authorized keys on other docker host for some_user IdentityFile ~/.ssh/this-docker-private-key 

Now you can just do ssh other_docker

+6
source share

I have not tested this yet, but you can do something like ssh hostUser@xxx.xxx.xxx.xxx 'ssh containerUser@xxx.xxx.xxx.xxx ' using the ssh command parameter.

0
source share

All Articles