码迷,mamicode.com
首页 > 其他好文 > 详细

通过ssh方式登陆Docker容器的操作记录

时间:2017-03-09 20:02:21      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:centos   get   eal   ase   learn   creat   ges   openssh   登陆   

 

前面几篇已经介绍了Docker基础环境的部署,下面介绍下通过ssh方式登陆Docker容器的操作记录

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos7             7.3.1611            d5ebea14da54        2 weeks ago         311 MB
<none>              <none>              d5c154b612c8        2 weeks ago         311 MB
test                latest              ecefde07358f        11 weeks ago        599.6 MB
learn/ping          latest              fea07d84b0df        4 months ago        196.7 MB
docker.io/tomcat    latest              ebb17717bed4        4 months ago        355.4 MB
docker.io/centos    latest              980e0e4c79ec        6 months ago        196.7 MB
nginx               1.9                 c8c29d842c09        9 months ago        182.7 MB
docker.io/redis     2.8.19              dd9fe7db5236        22 months ago       110.7 MB

[root@localhost ~]# docker run -i -t centos7:7.3.1611 /bin/bash

[root@a3c8baf6961e /]# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 

[root@a3c8baf6961e /]# yum install wget vim
[root@a3c8baf6961e /]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

安装ssh服务端
[root@a3c8baf6961e /]# yum cleal all
[root@a3c8baf6961e /]# yum install passwd
[root@a3c8baf6961e /]# yum install openssh-server  

修改容器密码
[root@a3c8baf6961e /]# echo "wangshibo@123" |passwd --stdin root

产生公私钥
[root@a3c8baf6961e /]# ssh-keygen -t rsa     //一路回车
[root@a3c8baf6961e /]# cd ~/.ssh/
[root@a3c8baf6961e .ssh]# ls
id_rsa  id_rsa.pub
[root@a3c8baf6961e .ssh]# cat id_rsa.pub > authorized_keys
[root@a3c8baf6961e .ssh]# ls
authorized_keys  id_rsa  id_rsa.pub

执行sshd命令,有报错:
[root@a3c8baf6961e .ssh]# /usr/sbin/sshd
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_dsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key

解决办法:
[root@a3c8baf6961e .ssh]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
[root@a3c8baf6961e .ssh]# ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
[root@a3c8baf6961e .ssh]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_ecdsa_key
[root@a3c8baf6961e .ssh]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_ed25519_key

再次执行sshd命令,如果没有报错,说明可以启动了
[root@a3c8baf6961e .ssh]# /usr/sbin/sshd
[root@a3c8baf6961e .ssh]# 

  

通过ssh方式登陆Docker容器的操作记录

标签:centos   get   eal   ase   learn   creat   ges   openssh   登陆   

原文地址:http://www.cnblogs.com/kevingrace/p/6526990.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!