I am able to render the public ip of a virtual machine on Chrome but not able to connect it with SSH, raising an error: connect to host xxx.xxx.xxx.xx port 22: Connection refused. When I check the virtual machine on Portal, there is no security group assigned to it. Is that something to do with this? How can I fix it?
1
votes
1 Answers
2
votes
According to your description, if we want to ssh to docker image, we should install SSH on this image, and open port for this image, I will run centos image for example:
docker pull centos:centos6
docker run -i -t centos:centos6
yum install openssh-server openssh-client(install ssh)
chkconfig sshd on
passwd(reset root password)
exit
docker commit 332b19ca916c centos/centosssh (commit this image)
docker run -i -t -d -p 50001:22 centos/centosssh (NAT for this container)
docker attach containerid (connect this container)
vi /etc/ssh/sshd_config (modify sshd config)
change UsePAM to no
service sshd start
Then open port 50001 in Azure NSG.
This time, we can use SSH to connect it:
Update:
I use CLI 2.0 to create a VM with docker extension, and change public IP address to static, and use command sudo docker run -d -p 80:80 nginx
to run container on the VM. then use chrome to test the nginx, it works fine, and I can ssh to the Azure VM with Public IP and FQDN.
the nginx container:
jason@MyDockerVM:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
61e10ebb6d22 nginx "nginx -g 'daemon ..." 4 minutes ago Up 4 minutes 0.0.0.0:80->80/tcp, 443/tcp kind_leavitt
Try to use FQDN to ssh host:
[c:\~]$ ssh jason@mypublicdns.eastus.cloudapp.azure.com
Host 'mypublicdns.eastus.cloudapp.azure.com' resolved to 52.186.123.151.
Connecting to 52.186.123.151:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.19.0-65-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Fri Apr 7 06:40:06 UTC 2017
System load: 0.31 Processes: 118
Usage of /: 5.8% of 28.80GB Users logged in: 1
Memory usage: 12% IP address for eth0: 10.0.0.4
Swap usage: 0% IP address for docker0: 172.17.0.1
Try to use public IP address to ssh the host:
[c:\~]$ ssh jason@52.186.123.151
Connecting to 52.186.123.151:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.19.0-65-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Fri Apr 7 06:40:55 UTC 2017
System load: 0.21 Processes: 119
Usage of /: 5.8% of 28.80GB Users logged in: 1
Memory usage: 12% IP address for eth0: 10.0.0.4
Swap usage: 0% IP address for docker0: 172.17.0.1
cloudapp.net
namespace. Perhaps edit your question with more details about the ports configured? – David Makogon