https://www.cnblogs.com/snooker/p/10963377.html
一、迁移/var/lib/docker目录
1、du -hs /var/lib/docker/ 命令查看磁盘使用情况。
root@nn0:~$ du -hs /var/lib/docker/
237G /var/lib/docker/
2、docker system df命令,类似于Linux上的df命令,用于查看Docker的磁盘使用情况:
root@nn0:~$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 7 2 122.2GB 79.07GB (64%)
Containers 2 2 61.96GB 0B (0%)
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
3、 docker system prune命令可以用于清理磁盘,删除关闭的容器、无用的数据卷和网络,以及dangling镜像(即无tag的镜像)。
root@nn0:~$ docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
4、 docker system prune -a命令清理得更加彻底,可以将没有容器使用Docker镜像都删掉。注意,这两个命令会把你暂时关闭的容器,以及暂时没有用到的Docker镜像都删掉了…所以使用之前一定要想清楚.。我没用过,因为会清理 没有开启的 Docker 镜像。
5、 迁移 /var/lib/docker 目录。
5.1、 停止docker服务。
systemctl stop docker
5.2、 创建新的docker目录,执行命令df -h,找一个大的磁盘。 我在 /home目录下面建了 /home/docker/lib目录,执行的命令是:
mkdir -p /home/docker/lib
5.3 、迁移/var/lib/docker目录下面的文件到 /home/docker/lib:
rsync -avz /var/lib/docker /home/docker/lib/
5.4、 配置 /etc/systemd/system/docker.service.d/devicemapper.conf。查看 devicemapper.conf 是否存在。如果不存在,就新建。
mkdir -p /etc/systemd/system/docker.service.d/
vi /etc/systemd/system/docker.service.d/devicemapper.conf
5.5 然后在 devicemapper.conf 写入:(同步的时候把父文件夹一并同步过来,实际上的目录应在 /home/docker/lib/docker )
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --graph=/home/docker/lib/docker
5.6、 重新加载 docker
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
5.7、 为了确认一切顺利,运行
# docker info
命令检查Docker 的根目录.它将被更改为 /home/docker/lib/docker
...
Docker Root Dir: /home/docker/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
...
5.8、 启动成功后,再确认之前的镜像还在:
root@nn0:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
AAA/AAA v2 7331b8651bcc 27 hours ago 3.85GB
BBB/BBB v1 da4a80dd8424 28 hours ago 3.47GB
4.9 确定容器没问题后删除/var/lib/docker/目录中的文件。
二、迁移/var/lib/docker目录后,Docker无法启动 (error initializing graphdriver: driver not supported)
启动信息
[root@nn0 ~]# systemctl start docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
启动详情
8月 31 01:47:25 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...
-- Subject: Unit docker.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.service has begun starting up.
8月 31 01:47:25 localhost.localdomain dockerd[2390]: time="2018-08-31T01:47:25.197015872+08:00" level=info msg="libcontainerd: new containerd process, pid: 2393"
8月 31 01:47:26 localhost.localdomain dockerd[2390]: time="2018-08-31T01:47:26.204103195+08:00" level=error msg="[graphdriver] prior storage driver overlay2 failed: driver not supported"
8月 31 01:47:26 localhost.localdomain dockerd[2390]: Error starting daemon: error initializing graphdriver: driver not supported
8月 31 01:47:26 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
8月 31 01:47:26 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
错误原因:error initializing graphdriver: driver not supported
解决办法:在 /etc/docker 目录下创建daemon.json文件,并且加入以下配置
touch daemon.json
vi daemon.json
{
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}
再次启动
systemctl start docker
问题解决
三、docker-runc not installed on system 问题
问题描述:
docker运行镜像的时候,报错如下:
[root@nn0 k8s]# docker run -it registry.helloworld.com/test/atsd:latest bash
WARNING: IPv4 forwarding is disabled. Networking will not work.
/usr/bin/docker-current: Error response from daemon: shim error: docker-runc not installed on system.
问题解决:
经过一番排查,如下解决方案有用:
[root@nn0 k8s]# cd /usr/libexec/docker/
[root@nn0 docker]# ln -s docker-runc-current docker-runc
以上,问题解决。