docker七:手动制作docker镜像
手动将容器保存为镜像:
docker commit 容器id或容器的名字 新的镜像名字[:版本号可选]
1):制作容器
示例:制作centos6.9容器,并添加一些软件
# docker run -it -p 1022:22 centos:6.9
ps -ef
查看容器中,是否有yum和ssh软件
which yum
which ssh
查看sshd软件的名字
[root@docker02 ~]# which sshd
/usr/sbin/sshd
[root@docker02 ~]# rpm -qf /usr/sbin/sshd
openssh-server-7.4p1-16.el7.x86_64
安装sshd软件:
yum install -y openssh-server
service sshd start
将生成3对sshd密钥对
# service sshd start
Generating SSH2 RSA host key: [ OK ]
Generating SSH1 RSA host key: [ OK ]
Generating SSH2 DSA host key: [ OK ]
Starting sshd: [ OK ]
设置容器的root密钥,以便从其它主机ssh连接到容器
# passwd root
ssh连接到容器:使用宿主机的IP加映射到容器的端口
# ssh root@192.168.1.12 -p 1022
添加dns解析:
# echo '192.168.1.11 mirrors.aliyum.com' >>/etc/hosts
修改yum源:传送宿主机上的repo到容器
curl -o /etc/yum.repos.d/CentOS-Base.repo http://192.168.155/repo/CentOS-7.repo
2).将容器提交为镜像
docker commit 9a575949b221 centos6-ssh-httpd:v1
查看镜像列表:
docker images
3).创建一个新容器,测试镜像功能是否可用
docker run -d -p 3022:22 centos6-ssh-httpd:v1 /usr/sbin/sshd -D
或者
docker run -it centos6-ssh-httpd:v1
posted on 2019-08-05 17:16 myworldworld 阅读(148) 评论(0) 收藏 举报