拉取镜像
docker pull centos:centos8
启动容器
docker run -d -p 10022:22 --name service1 --privileged=true sshd_centos
添加–privateged参数是为了使容器内的root拥有真正的root权限,否则不能使用systemctl管理系统
进入容器
docker exec -it service1 /bin/bash
配置服务器
cd /etc/yum.repos.d
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
安装软件
dnf install -y vim net-tools openssh* passwd
设置密码
passwd root
启动ssh
systemctl start sshd