根据你的描述,如果我们想ssh到docker镜像,我们应该在这个镜像上安装SSH,并为这个镜像打开端口,我以运行centos镜像为例:
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
然后在 Azure NSG 中打开 50001 端口。
这一次,我们可以使用 SSH 来连接它:
更新:
我使用 CLI 2.0 创建一个带有 docker 扩展的 VM,并将公共 IP 地址更改为 static,并使用命令 sudo docker run -d -p 80:80 nginx 在 VM 上运行容器。然后使用 chrome 测试 nginx,它工作正常,我可以通过 Public IP 和 FQDN SSH 到 Azure VM。
nginx 容器:
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
尝试使用 FQDN ssh 主机:
[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
尝试使用公网IP地址ssh主机:
[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