[root@dime source]# cat centos-6-x86_64-minimal.tar.gz | docker import - centos-6-x86_64
7996b1e6f7eaac8034f414c3c9c232dcefe515262056847f68da51252be50cde
[root@dime source]# docker images ;查看docker镜像
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos-6-x86_64 latest 7996b1e6f7ea 41 seconds ago 326.4 MB
Step2:在Docker主机上创建本地密钥 1、创建一个RSA类型,长度为2048的密钥
[root@dime ~]# ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
2e:8b:d0:af:38:83:ba:b2:39:a8:2c:e3:04:48:e7:02 root@dime.huangming.org
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
|E. . |
|+ o |
|o. . S |
|. .. . |
|.o. . . . |
|X.oo o o |
|%B.oo.o |
+-----------------+
[root@dime ~]# ls ~/.ssh/
id_rsa id_rsa.pub known_hosts
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
499c9a0bc965 centos_lnmpt "bash" 4 minutes ago Up 4 minutes 0.0.0.0:33322->22/tcp, 0.0.0.0:33380->80/tcp, 0.0.0.0:33306->3306/tcp, 0.0.0.0:38080->8080/tcp dnode2
3f63e6ba4d83 centos_lnmpt "bash" About an hour ago Up About an hour 0.0.0.0:32775->22/tcp, 0.0.0.0:32774->80/tcp, 0.0.0.0:32773->3306/tcp, 0.0.0.0:32772->8080/tcp dnode1
2、进入已开启的容器
#进入dnode1容器
[root@dime dockerdir]# docker exec -it dnode1 bash
[root@3f63e6ba4d83 /]# ls /usr/local/
apache-tomcat-8.0.33 doc include lib64 libiconv php src
bin etc jpeg6 libexec mysql sbin tomcat
cmake games lib libgd2 nginx share
#启动Nginx
[root@3f63e6ba4d83 /]# nginx
[root@3f63e6ba4d83 /]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
#进入dnode2容器
[root@dime ~]# docker exec -it dnode2 bash
#启动Tomcat
[root@a405702fbe84 /]# catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@a405702fbe84 /]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
LISTEN 0 100 :::8009 :::*
LISTEN 0 100 :::8080 :::*
Step5:SSH远程管理容器主机
前面在构造Dockerfile时,已经将宿主机的ssh公钥发送到容器镜像里,因此,只需要将容器的sshd服务启动,即可以通过ssh远程登陆容器进行管理
#dnode1
[root@3f63e6ba4d83 /]# service sshd start
Generating SSH2 RSA host key: [ OK ]
Generating SSH1 RSA host key: [ OK ]
Generating SSH2 DSA host key: [ OK ]
Starting sshd: [ OK ]
[root@3f63e6ba4d83 /]# exit
exit
#dnode2
[root@a405702fbe84 /]# service sshd start
Generating SSH2 RSA host key: [ OK ]
Generating SSH1 RSA host key: [ OK ]
Generating SSH2 DSA host key: [ OK ]
Starting sshd: [ OK ]
[root@a405702fbe84 /]# exit
exit
远程登陆dnode1和dnode2
[root@dime ~]# ssh root@192.168.1.15 -p 32775
The authenticity of host '[192.168.1.15]:32775 ([192.168.1.15]:32775)' can't be established.
RSA key fingerprint is 36:34:32:82:25:ba:6b:e4:b9:40:7e:98:a2:6d:de:3c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.1.15]:32775' (RSA) to the list of known hosts.
[root@3f63e6ba4d83 ~]#
[root@dime ~]# ssh root@192.168.1.15 -p 33322
The authenticity of host '[192.168.1.15]:33322 ([192.168.1.15]:33322)' can't be established.
RSA key fingerprint is 2e:18:d1:0c:26:cb:d2:2d:37:9a:0d:a7:6d:0d:1e:2c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.1.15]:33322' (RSA) to the list of known hosts.
[root@499c9a0bc965 ~]#