docker error: no space left on device 问题及解决

当运行Docker容器时遇到'no space left on device'错误,可以通过更新docker.service文件或更改Docker根目录来解决。更新服务文件未解决问题,但改变Docker根目录成功释放了更多磁盘空间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【运行】

docker run -i -t 镜像名 /bin/bash

【报错】

docker: write /var/lib/docker/tmp/GetImageBlob167182478: no space left on device.

【解决方案1】更新docker.serive文件——未解决

ubuntu - Docker error : no space left on device - Stack Overflowicon-default.png?t=M0H8https://stackoverflow.com/a/56126715

If you are facing this issue even after below command:

docker system prune --all

The solution which worked finally:

  1. docker info
    • To check current docker storage driver
    • Mine was : Storage Driver: devicemapper; If you have storage driver as overlay2 nothing to worry about. Solution will still work for you.
  2. df -h
    • This is to check the available file systems on machine and the path where they are mounted. Two mounted path to have a note:
    • /dev/mapper/rootvg-var 7.6G 1.2G 6.1G 16% /var
    • /dev/mapper/rootvg-apps 60G 9.2G 48G 17% /apps
    • Note- By default docker storage path is /var/lib/docker. It has available space ~6 GB and hence all the space related issues. So basically, I have to move default storage to some other storage where available space is more. For me its File sysyem path '/dev/mapper/rootvg-apps' which is mounted on /apps. Now task is to move /var/lib/docker to something like /apps/newdocker/docker.
  3. mkdir /apps/newdocker/docker
  4. chmod -R 777 /apps/newdocker/docker
  5. Update docker.serive file on linux which resides under: /usr/lib/systemd/system
    • vi /usr/lib/systemd/system/docker.service
  6. if storage device is devicemapper , comment existing ExecStart line and add below under [Service]:
    • ExecStart=
    • ExecStart=/usr/bin/dockerd -s devicemapper --storage-opt dm.fs=xfs --storage-opt dm.basesize=40GB -g /apps/newdocker/docker --exec-opt native.cgroupdriver=cgroupfs
  7. Or if storage device is overlay2:
    • just add -g /apps/newdocker/docker in the existing ExexStart statement.
    • Something like ExecStart=/usr/bin/dockerd -g /apps/newdocker/docker -H fd:// --containerd=/run/containerd/containerd.sock
  8. rm -rf /var/lib/docker (It will delete all existing docker data)
  9. systemctl stop docker
  10. ps aux | grep -i docker | grep -v grep
    • If no output has been produced by the above command, reload systemd daemon by below command.
  11. systemctl daemon-reload
  12. systemctl start docker
  13. docker info
    • Check out the Data Space Available: 62.15GB after mouting to docker to new File system.
  14. DONE

【解决方案2】docker change root directory——已解决

IBM Docs

  1. Stop the Docker services:
    sudo systemctl stop docker
    sudo systemctl stop docker.socket
    sudo systemctl stop containerd
  2. Create the necessary directory structure into which to move Docker Root by running the following command. This directory structure must reside on a file system with at least 50GB free disk space. Significantly more disk space may be required depending on your daily ingestion volumes and data retention policy:
    sudo mkdir -p /new_dir_structure
  3. Move Docker Root to the new directory structure:
    sudo mv /var/lib/docker /new_dir_structure
  4. Edit the file /etc/docker/daemon.json. If the file does not exist, create the file by running the following command:
    sudo vim /etc/docker/daemon.json
    Add the following information to this file:
    {
      "data-root": "/new_dir_structure/docker”
    }
  5. After the /etc/docker/daemon.json file is saved and closed, restart the Docker services:
    sudo systemctl start docker
    After you run the command, all Docker services through dependency management will restart.
  6. Validate the new Docker Root location:
    docker info -f '{{ .DockerRootDir}}'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值