不通过SSH接入Docker,SSH接入Docker


翻译自:http://www.sebastien-han.fr/blog/2014/01/27/access-a-container-without-ssh/

先运行一个简单的memcache容器:

1 2 3 4 5 6 $ sudo docker run -d -p 11211 bacongobbler/memcached memcached /usr/bin/memcached -m 64 -p 11211 -u memcache -l 0.0.0.0   $ sudo docker ps CONTAINER ID        IMAGE                                      COMMAND                CREATED             STATUS              PORTS                      NAMES 0a9856723f90        192.168.0.127:5042/memcached:latest        memcached /usr/bin/m   2 seconds ago       Up 2 seconds        0.0.0.0:49153->11211/tcp   pensive_pasteur  

获得运行在docker中进程的pid:

1 2 3 root@docker:~# ps faux |grep memcached syslog   29123  0.0  0.0 323216  1184 ?        Sl   22:40   0:00          \_ memcached /usr/bin/memcached -m 64 -p 11211 -u memcache -l 0.0.0.0  

安装nsenter命令(util-linux包中),需要2.23release的linux。

1 2 3 4 5 6 7 $ wget https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.bz2 $ bzip2 -d -c util-linux-2.24.tar.bz2 | tar xvf - $ cd util-linux-2.24/ $ sudo ./configure --without-ncurses $ make nsenter $ cp nsenter /usr/local/bin  

然后,我们连接进入docker容器。

1 2 3 4 5 6 7 $ sudo nsenter -m -u -i -n -p -t 29123 /bin/sh # ps faux USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND root        11  0.0  0.0   4396   608 ?        S    22:41   0:00 /bin/sh root        12  0.0  0.0  15272  1100 ?        R+   22:41   0:00  \_ ps faux memcache     1  0.0  0.0 323216  1184 ?        Sl   22:40   0:00 memcached /usr/bin/memcached -m 64 -p 11211 -u memcache -l 0.0.0.0  

ssh连不上解决方法

那是你的SSH密码修改过了!用iFunBox可以查SSH的密码!打开iFunBox 然后点文件-首选项-显示OpenSSH的密码!在把密码复制到手编跳出来的框框上!用户名不用改!这样就能连上了!
 

linux 可以PING通,但SSH连接不上,怎解决?

这个原因可能比较多,例如:被防火墙挡掉,ssh服务配置文件中的参数是否拒绝了连接等等。我说一种最可能出现的吧,清除/root/.ssh/known_hosts文件中和你所要连接的ip或者主机名有关的ssh加密Key。
 

相关内容