Docker创建centos7

下载centos镜像

docker pull centos

运行容器,修改镜像

  • 运行

docker run -itd --name centos7 centos /bin/bash
  • 进入centos,配置环境

docker exec -it centos7 /bin/bash
yum search ifconfig
yum install net-tools.x86_64
yum list openssh
yum install -y vim
yum install -y openssh-server
yum install -y openssh-clients
yum install -y wget
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache

保存镜像

  • 保存修改

docker commit centos7 zzq_image_centos7:v1.0
  • 保存到本地

docker save zzq_image_centos7:v1.0 > G:\\Docker_Images\\centos7_update.jar

关闭当前运行的镜像

  • 停止运行后台

docker stop centos7
  • 查询连接

docker ps -a
  • 删除其它连接

docker rm f865a757696d
  • 载入镜像

docker load < G:\\Docker_Images\\centos7_update.jar

运行镜像

  • 打开镜像的22端口映射到8080端口上

docker run -itd -p 8080:22 -e "container=docker" --privileged=true --name centos7 zzq_image_centos7:v1.0 /usr/sbin/init
  • 进入centos7镜像内

docker exec -it centos7 /bin/bash
  • 查看22端口是否启动

ps -ef | grep ssh

启动命令

systemctl start sshd

修改root密码

passwd root

通过xshell等工具连接

  • 查看本地docker的地址

ipconfig /all

以太网适配器 vEthernet (DockerNAT):

   连接特定的 DNS 后缀 . . . . . . . :
   描述. . . . . . . . . . . . . . . : Hyper-V Virtual Ethernet Adapter #2
   物理地址. . . . . . . . . . . . . : 00-15-5D-4B-C1-02
   DHCP 已启用 . . . . . . . . . . . : 否
   自动配置已启用. . . . . . . . . . : 是
   IPv4 地址 . . . . . . . . . . . . : 10.0.75.1(首选)
   子网掩码  . . . . . . . . . . . . : 255.255.255.240
   默认网关. . . . . . . . . . . . . :
   DNS 服务器  . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                       fec0:0:0:ffff::2%1
                                       fec0:0:0:ffff::3%1
   TCPIP 上的 NetBIOS  . . . . . . . : 已启用
  • xshell连接

输入上面IPv4地址,然后端口为【8080】,正常账号密码输入连接即可
发布了38 篇原创文章 · 获赞 15 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/u013057271/article/details/104482849
今日推荐