1、打包
[root@docker1 ~]# docker save -o centos.tar centos:latest
[root@docker1 ~]# systemctl start docker
[root@docker1 ~]# docker ps -all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e84261634543 centos:latest "/bin/bash" 20 hours ago Exited (0) 2 minutes ago c0
[root@docker1 ~]# docker rm c0
c0
[root@docker1 ~]# docker load -i centos.tar
[root@docker1 ~]# docker run -it --name c0 centos:latest /bin/bash
[root@docker1 ~]# docker start c0
c0
[root@docker1 ~]# docker attach c0
[root@c8d84a3be144 /]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@c8d84a3be144 /]# yum clean all && yum makecache
[root@c8d84a3be144 /]# yum -y install epel-release
[root@c8d84a3be144 /]# read escape sequence
[root@docker1 ~]# docker ps -all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c8d84a3be144 centos:latest "/bin/bash" 30 minutes ago Up 8 minutes c0
2、从容器导出tar包
[root@docker1 ~]# docker export -o centos_yum.tar c0 #容器包
[root@docker1 ~]# ls #查看新生成的tar包
anaconda-ks.cfg centos.tar#镜像包 centos_yum.tar
3、从tar包导入镜像
docker import -m 说明内容 centos_yum.tar centos:yum
[root@docker1 ~]# docker import -m yum centos_yum.tar centos:yum #生成镜像
4、查看镜像 新的镜像不需要配置yum
[root@docker ~]# docker run -it --name c1 centos:httpd /bin/bash
5、练习 创建一个镜像,包含httpd服务,名称centos版本httpd
[root@ac4bae6c2a0d /]# rm -rf /etc/yum.repos.d/*
[root@ac4bae6c2a0d /]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@ac4bae6c2a0d /]# yum clean all && yum makecache
[root@ac4bae6c2a0d /]# yum -y install httpd
[root@ac4bae6c2a0d /]# echo "docker_httpd_server" > /var/www/html/index.html
[root@ac4bae6c2a0d /]# http -k start
[root@ac4bae6c2a0d /]# http -k start
[root@ac4bae6c2a0d /]# curl localhost
docker_httpd_server
[root@docker ~]# docker export -o centos_yum.tar c0
[root@docker ~]# docker import -m yum centos_yum.tar centos:httpd
[root@docker ~]# docker run -it --name c1 centos:httpd /bin/bash
[root@c75fd2f052ea /]# httpd -k start
[root@c75fd2f052ea /]# curl localhost
docker_httpd_server
[root@docker ~]# docker inspect c1
6、在外部调用指令
[root@docker ~]# docker exec c0 ip a
[root@docker ~]# docker exec c0 ifconfig
7、外部创建文件
[root@docker ~]# docker exec c1 touch /opt/test.txt
[root@docker ~]# docker exec c1 ls /opt/
test.txt
二、总结
1.镜像的迁移
1.打包
docker save -o centos.tar centos: latest
2.加载
docker load -i centos.tar
docker images
#停用关闭容器
docker stop c0 c1;docker rm c0 c1
删除镜像
docker rmi centos:latest
2.创建镜像
1.创建容器
docker run -it -- name c0 centos:latest /bin/bash
下载阿里云仓库
clean, ,,makecache
ctrl p q
2.容器打包
docker export -o centos_yum. tar c0
3.引入镜像
docker import -m "update yum repo" centos_yum. tar
centos : yum
docker image ls
3.ip网络
1.交互式
docker start c0
docker attach c0
yum -y install iproute
ip a
2.inspect
docker inspect c0
3.exec
docker exec c0 yum -y install net-tools
docker exec c0 ifconfig
4.端口映射
1.指定端口映射
docker run -it -- name c0 -p70:80 centos:httpd
/bin/bash
2.随机端口映射
docker run -it -- name c1 -p80 centos:httpd
/bin/bash
3.指定其他ip的端口映射
ifconfig ens33:0 192.168.71.51 broadcast
192.168.71.51 netmask 255.255.255.255 up
docker run -it -- name c2 -p192.168.71.51 :: 80
centos:httpd /bin/bash
5.持久化
1.挂载
docker run -it -- name c3 -v /abc:/def centos:httpd
/bin/bash
touch /abc/aaa. txt
docker exec c3 ls /def