0

I have created two EC2 instances (let's call them the client and remote hosts) inside the same private subnet, and I have launched a Docker container inside the remote host.

The docker container itself is part of a docker network, with the IP "192.168.125.2".

I have started an sshd server inside this container, and mapped port 22 to 2201, inside and outside the container respectively.

Here is my issue: if I try to ssh inside the docker container, from the client host, using my public IP, like so:

ssh -p 2201 username@PUBLIC_IP

Then, even though it takes a long while, I can ssh into the container in the remote host.

If however I try to ssh the container from the client host using the private IP

 ssh -p 2201 username@PUBLIC_IP

I get a timeout error, and cannot access the docker container.

I should add that if I try to ssh the remote host from the local host (without accessing the docker container) , like so:

 ssh -p 22 username@PRIVATE_IP

then I can ssh with no issues.

What could be the issue here? How can I ssh from my client to a container in my remote host, using private IP addresses?

I have added inbound rules to allow traffic for ports 2201 and 2202 from any source, disabled source/destination IP check, but still it had no effect.

Thank you.

UPDATE 1:

Here is the output for docker port <container_name>

5672/tcp -> 0.0.0.0:5672
7777/tcp -> 0.0.0.0:7777
22/tcp -> 0.0.0.0:2201
  • could you give us the output of docker port {container-name} – trozz May 19 '18 at 1:32
  • You've said your instances are in a private subnet and then you try to ssh to a public IP. I imagine there's no route. However your post has a lot of ambiguity. Suggest you edit to more precisely define your environment, your instance IPs, your public IP, relevant docker config and IPs, and the exact commands that aren't working. – Tim May 19 '18 at 1:49
  • @trozz, I have added the output to the question. – manuel mourato May 19 '18 at 13:28
  • I suggest first enable icmp traffic in security group and try to ping from client to remote's ip address. Mostly it wont work, now in the ICMP rule add source ip as the name of the "<<SecurityGroup>>". This will enable access between EC2 belonging to that security group. If that works, then similarly add source ip as the name of the "<<SecurityGroup>>" in your 2201 rule and also 22 rule. Then try your ssh see if it works. – Narain May 21 '18 at 19:01
0

I suggest first enable icmp traffic in security group and try to ping from client to remote's ip address. Mostly it wont work, now in the ICMP rule add source ip as the name of the "<>". This will enable access between EC2 belonging to that security group. If that works, then similarly add source ip as the name of the "<>" in your 2201 rule and also 22 rule. Then try your ssh see if it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.