Published on

docker 容器和镜像的备份

Authors

本地备份

  1. 运行一个容器
docker run -itd --name ubuntu_push_test ubuntu /bin/bash
  • 若容器没有启动,可以手动启动一下

    ubuntu_push_test 为容器的名字,也可以换成容器的 ID

docker start ubuntu_push_test
  • 查看当前启动中的容器
dockder container ls

image-20221029154833477

  1. 提交
docker commit -m "first commit" -p ubuntu_push_test first_push

其中first commit 为你的提交信息, ubuntu_psuh_test为你的容器名称, first_push为你要 push 的镜像

  1. 保存到本地宿主机中
 docker save -o ~/first_save.tar first_push

image-20221029155516252

至此,我们就完成了将镜像保存到本地宿主机的操作,如果想加载本地的 tar 文件的话,可以使用 command:

docker load -i ~/first_save.tar

远程备份

  1. 登录 docker 账号
docker logout
docker login
// 然后输入你的密码即可登录
  1. 将本地的镜像打包
docker tag first_push xiaoduoge/ubuntu:latest

first_push 为你要 push 的镜像, xiaoduoge为你的用户名, ubuntu是你的镜像名,这里也可以是first_push,没有关系; latest是你自定义的版本号。

  1. push
docker push xiaoduoge/ubuntu:latest
  1. pull

    docker pull xiaoduoge/ubuntu:latest
    

\wsl$

docker build -t xiaoduoge/workenv .

docker run -t -i xiaoduoge/workenv /bin/zsh