http://www.voycn.com/article/xshelllianjiedockerhuanjingzhongdeubuntu
docker search ubuntu
docker pull ubuntu
docker images
运行:
docker run -it ubuntu:latest /bin/bash
进入ubuntu:
apt-get install git vim openssh-client openssh-server net-tools build-essential software-properties-common curl wget tmux ack-grep
docker ps -a #查看container 的id信息
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
5a3e0f4478b4 ubuntu:latest "/bin/bash" 31 minutes ago Up 31 minutes
determined_babbage
然后重新开一个terminal,保存container
$ docker commit 5a3e0f4478b4 scott/ubuntu
sha256:8466a6c1d92b6285c70cef0a4425c7aea9c909f6f6cfb5fe1d41ccaf19d17f2b
4.重新运行Container
docker run -it -p 3322:22 scott/ubuntu /bin/bash
service ssh start
注意-p 3322:22这句,意思是将docker的3322端口和container的22端口绑定,这样访问docker的3322等价于访问container的22端口
5.ssh连接container
你可以用xshell或putty等ssh客户端工具连接container
请先给root设置一个密码,然后修改下/etc/ssh/sshd_config文件
将PermitRootLogin的值修改为yes
首先假设各方的ip如下:
本地windows ip: 192.168.99.1
docker ip:192.168.99.100
container ip:172.17.0.3
那么,你要远程container,则要访问以下地址:
ssh 192.168.99.100:3322
这样通过访问docker的3322端口,就神奇的间接连通到container的22端口了,从而达到ssh连接container的目的,至此。
关于docker下命令自动补全
在ubuntu下安装bash-completion
安装成功后,得到文件为 /usr/share/bash-completion/bash_completion,如果没有这个文件,则说明系统上没有安装这个工具。
source /usr/share/bash-completion/bash_completion
source /usr/share/bash-completion/completions/docker