[root@centos7 ~]# docker images|grep centos
centos latest 0d120b6ccaa8 4 days ago 215MB
[root@centos7 ~]#
导出镜像:
[root@centos7 ~]# docker save centos > /root/centos.tar.gz
[root@centos7 ~]# ll
total 217160
-rw-------. 1 root root 1571 May 18 2019 anaconda-ks.cfg
-rw-r--r--. 1 root root 222366720 Aug 15 23:46 centos.tar.gz
[root@centos7 ~]#
导入镜像:
[root@centos7 ~]# docker load < /root/centos.tar.gz
Loaded image: centos:latest
[root@centos7 ~]#
启动容器:
[root@centos7 ~]# docker run --name mydocker -ti centos /bin/bash
[root@ccf8a20bd407 /]#
[root@ccf8a20bd407 /]#
进入:
[root@centos7 ~]# docker attach mydocker
[root@centos7 ~]# yum install -y util-linux
[root@centos7 ~]# docker inspect -f '{{.State.Pid}}' mydocker
38547
[root@centos7 ~]# nsenter -t 38547 -m -u -i -n -p
[root@ccf8a20bd407 /]#
[root@centos7 ~]# docker exec -it mydocker /bin/bash
[root@ccf8a20bd407 /]#
将容器保存为镜像:
[root@centos7 ~]# docker ps -a|grep mydocker
ccf8a20bd407 centos "/bin/bash" 16 minutes ago Up 10 minutes mydocker
[root@centos7 ~]#
[root@centos7 ~]#
[root@centos7 ~]# docker commit -m 'this-is-a-images' ccf8a20bd407 oldboy/my-centos:v1
sha256:1432890ec09ab6fce4c27fa3a91c8281e7718cfd852c3d142ee5357b09b127e0
[root@centos7 ~]#
[root@centos7 ~]# docker images|grep centos
oldboy/my-centos v1 1432890ec09a 15 seconds ago 215MB
centos latest 0d120b6ccaa8 4 days ago 215MB
[root@centos7 ~]#