docker run -it --name node1 docker.io/centos bash 创建node1容器
docker exec -it node1 bash 进入node1
yum install openssh-server –y 安装ssh
yum install net-tools –y 安装ifconfig
现象:启动sshd服务时,虽看似服务启动成功,但客户端并不能连接上sshd服务器端。
如下:
- [[email protected] ~]# /usr/sbin/sshd
- Could not load
host key: /etc/ssh/ssh_host_rsa_key - Could not load
host key: /etc/ssh/ssh_host_ecdsa_key - Could not load
host key: /etc/ssh/ssh_host_ed25519_key
cd /etc/ssh/ 创建密钥
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t ecdsa
-f /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key
- [[email protected] ~]# ll /etc/ssh/
- total 276
- -rw-r--r-- 1 root root 242153 Mar 21 22:18 moduli
- -rw-r--r-- 1 root root 2208 Mar 21 22:18
ssh_config - -rw------- 1 root root 227 May 22 16:48 ssh_host_ecdsa_key
- -rw-r--r-- 1 root root 179 May 22 16:48
ssh_host_ecdsa_key.pub - -rw------- 1 root root 411 May 22 16:48 ssh_host_ed25519_key
- -rw-r--r-- 1 root root 99 May 22 16:48
ssh_host_ed25519_key.pub - -rw------- 1 root root 1679 May 22 16:48 ssh_host_rsa_key
10. -rw-r--r-- 1 root root 399 May 22 16:48
ssh_host_rsa_key.pub
11. -rw------- 1 root root 4361 Mar 21 22:18 sshd_config
/usr/sbin/sshd & 开启ssh
netstat -ntlup|grep 22 查看端口
tcp
0 0 0.0.0.0:22 0.0.0.0:* LISTEN 32/sshd
tcp6
0 0 :::22 :::* LISTEN 32/sshd
passwd修改root密码
做成镜像
docker commit -m ‘add centos_sshd images‘
node1 new/centos_sshd
此容器名 新镜像名
查看镜像
docker images
用镜像生成的容器不需要端口映射即可远程
登陆(用户/密码 hello/123456)
docker login 127.0.0.1:5000
重命名
docker tag 276408de9b28 127.0.0.1:5000/hello/centos_sshd
上传
docker push 127.0.0.1:5000/hello/centos_sshd
查看是否上传成功
docker images
原文地址:https://www.cnblogs.com/leiwenbin627/p/11213337.html