下载镜像
docker pull centos:7.6.1810
构建容器
docker run --name centos_a -dit -p 30522:22 centos:7.6.1810 /bin/bash
进入容器
docker attach centos_a
yum search ifconfig
yum install -y net-tools.x86_64
yum install -y openssh-server
ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ''
ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N ''
sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config
sed -i "s/#PubkeyAuthentication.*/PubkeyAuthentication yes/g" /etc/ssh/sshd_config
/usr/sbin/sshd -D &
passwd
ps -e | grep sshd
netstat -an | grep 22
CTRL+P+Q #退出容器,但不停止
来源:oschina
链接:https://my.oschina.net/u/4300604/blog/3611221