1、安装docker、不介绍了 自行安装
2、查找需要的镜像
docker search centos
3、拉取镜像
docker pull centos:centos7
4、查看本机镜像
docker images
5、启动镜像
docker run -itd --name <别名唯一> <镜像ID>
6、查看运行中的容器
docker ps
7、通过查看运行中的容器获取容器id 进入容器
docker exec -it <容器ID> bash
8、在容器安装需要得软件
#安装ssh
yum install -y openssh-server openssh-clients
#修改密码命令
yum install -y passwd
#service命令
yum install -y initscripts
#修改密码命令
passwd
#修改sshd_config配置文件
vi /etc/ssh/sshd_config
#找到UsePAM参数,设置为no
#重启ssh
service sshd start
#这里会报错
System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down
#直接进行下面的命令就行,使用最后一步的命令启动就解决这个问题了
退出容器
exit
9、保存为新的镜像
docker commit <容器ID> <镜像名称>
10、启动新的镜像
docker run -tid --name <别名唯一> --p 50022:22 --privileged=true <镜像ID> /sbin/init
说明 在容器内安装所需得环境需重新保存为新得镜像否则容器停止后会回到保存前得初始化、
或者使用文件挂载方式保存