1、遷移/var/lib/docker目錄html
一、du -hs /var/lib/docker/ 命令查看磁盤使用狀況。docker
root@nn0:~$ du -hs /var/lib/docker/ 237G /var/lib/docker/
二、docker system df命令,相似於Linux上的df命令,用於查看Docker的磁盤使用狀況:json
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
三、 docker system prune命令能夠用於清理磁盤,刪除關閉的容器、無用的數據卷和網絡,以及dangling鏡像(即無tag的鏡像)。bash
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
四、 docker system prune -a命令清理得更加完全,能夠將沒有容器使用Docker鏡像都刪掉。注意,這兩個命令會把你暫時關閉的容器,以及暫時沒有用到的Docker鏡像都刪掉了…因此使用以前必定要想清楚.。我沒用過,由於會清理 沒有開啓的 Docker 鏡像。網絡
五、 遷移 /var/lib/docker 目錄。app
5.一、 中止docker服務。dom
systemctl stop docker
5.二、 建立新的docker目錄,執行命令df -h,找一個大的磁盤。 我在 /home目錄下面建了 /home/docker/lib目錄,執行的命令是:ide
mkdir -p /home/docker/lib
5.3 、遷移/var/lib/docker目錄下面的文件到 /home/docker/lib:ui
rsync -avz /var/lib/docker /home/docker/lib/
5.四、 配置 /etc/systemd/system/docker.service.d/devicemapper.conf。查看 devicemapper.conf 是否存在。若是不存在,就新建。spa
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.六、 從新加載 docker
systemctl daemon-reload systemctl restart docker systemctl enable docker
5.七、 爲了確認一切順利,運行
# 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.八、 啓動成功後,再確認以前的鏡像還在:
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/目錄中的文件。
2、遷移/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
問題解決
3、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
以上,問題解決。