环境介绍:
CentOS 7.5 Docker 13.1.1
查看Docker默认存储目录:
[root@localhost ~]# yum -y install docke [root@localhost ~]# systemctl start docker [root@localhost ~]# systemctl enable docker [root@localhost ~]# docker info //查看docker基本信息 ... Docker Root Dir: /var/lib/docker //默认为/var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Experimental: false ...
备份已有镜像并修改默认存储目录:
1.查看挂载的磁盘
[root@localhost ~]# df -h //显示挂载情况 文件系统 容量 已用 可用 已用% 挂载点 ... /dev/sdb1 20G 33M 20G 1% /mnt/data
2.备份当前已有镜像
docker save -o 文件名.tar 镜像名
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/nginx latest 602e111c06b6 2 days ago 127 MB [root@localhost ~]# docker save -o /mnt/nginx.tar docker.io/nginx //备份当前已有的镜像 [root@localhost ~]# docker rmi 60
3.停止docker并修改配置文件
[root@localhost ~]# systemctl stop docker [root@localhost ~]# vim /etc/docker/daemon.json { "registry-mirrors": ["http://hub-mirror.c.163.com"], "graph": "/mnt/data" //添加存储路径 }
导入镜像并查看修改后存储路径
1.导入备份的镜像文件
docker load --input 镜像文件.tar
docker load < 镜像文件.tar
[root@localhost ~]# systemctl start docker [root@localhost ~]# docker load --input /mnt/nginx.tar 或者 docker load < /mnt/nginx.tar c2adabaecedb: Loading layer [==================================================>] 72.49 MB/72.49 MB 216cf33c0a28: Loading layer [==================================================>] 58.11 MB/58.11 MB b3003aac411c: Loading layer [==================================================>] 3.584 kB/3.584 kB Loaded image: docker.io/nginx:latest [root@localhost ~]# docker images //查看导入后镜像 REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/nginx latest 602e111c06b6 2 days ago 127 MB
2.查看修改后的存储路径
[root@localhost ~]# docker info ... Docker Root Dir: /mnt/data //存储路径已修改 Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: http://hub-mirror.c.163.com