docker系统中varlibdockeroverlay2占⽤很⼤,清理Docker占⽤的。。
⼀、迁移/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 72122.2GB 79.07GB (64%)
Containers 2261.96GB 0B (0%)
Local Volumes 00 0B 0B
Build Cache 00 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.f。查看 f 是否存在。如果不存在,就新建。
mkdir -p /etc/systemd/system/docker.service.d/
vi /etc/systemd/system/docker.service.f
5.5 然后在 f 写⼊:(同步的时候把⽗⽂件夹⼀并同步过来,实际上的⽬录应在 /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: 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.
启动详情
container容器用法
8⽉3101:47:25 localhost.localdomain systemd[1]: Starting Docker Application
-- Subject: Unit docker.service has begun start-up
-- Defined-By: systemd
-- Support: /mailman/listinfo/systemd-devel
--
-- Unit docker.service has begun starting up.
8⽉3101: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⽉3101: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⽉3101:47:26 localhost.localdomain dockerd[2390]: Error starting daemon: error initializing graphdriver: driver not supported
8⽉3101:47:26 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
8⽉3101: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运⾏镜像的时候,报错如下:
[root@nn0 k8s]# docker run -it registry.helloworld/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
以上,问题解决。 

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。