Why is docker image eating up my disk space that is not used by docker

前端 未结 9 2041
长发绾君心
长发绾君心 2020-12-12 11:07

I have setup docker and I have used completely different block device to store docker\'s system data:

[root@blink1 /]# cat /etc/sysconfig/docker
# /etc/sysc         


        
相关标签:
9条回答
  • 2020-12-12 11:52

    Deleting my entire /var/lib/docker is not ok for me. These are a safer ways:

    Solution 1:

    The following commands from the issue clear up space for me and it's a lot safer than deleting /var/lib/docker or for Windows check your disk image location here.

    Before:

    docker info
    

    Example output:

    Metadata file: 
    Data Space Used: 53.38 GB
    Data Space Total: 53.39 GB
    Data Space Available: 8.389 MB
    Metadata Space Used: 6.234 MB
    Metadata Space Total: 54.53 MB
    Metadata Space Available: 48.29 MB
    

    Command in newer versions of Docker e.g. 17.x +

    docker system prune -a
    

    It will show you a warning that it will remove all the stopped containers,networks, images and build cache. Generally it's safe to remove this. (Next time you run a container it may pull from the Docker registry)

    Example output:

    Total reclaimed space: 1.243GB
    

    You can then run docker info again to see what has been cleaned up

    docker info
    

    Solution 2:

    Along with this, make sure your programs inside the docker container are not writing many/huge files to the file system.

    Check your running docker process's space usage size

    docker ps -s #may take minutes to return
    

    or for all containers, even exited

    docker ps -as #may take minutes to return
    

    You can then delete the offending container/s

    docker rm <CONTAINER ID>
    

    Find the possible culprit which may be using gigs of space

    docker exec -it <CONTAINER ID> "/bin/sh"
    du -h
    

    In my case the program was writing gigs of temp files.

    (Nathaniel Waisbrot mentioned in the accepted answer this issue and I got some info from the issue)


    OR

    Commands in older versions of Docker e.g. 1.13.x (run as root not sudo):

    # Delete 'exited' containers
    docker rm -v $(docker ps -a -q -f status=exited)
    
    # Delete 'dangling' images (If there are no images you will get a docker: "rmi" requires a minimum of 1 argument)
    docker rmi $(docker images -f "dangling=true" -q)
    
    # Delete 'dangling' volumes (If there are no images you will get a docker: "volume rm" requires a minimum of 1 argument)
    docker volume rm $(docker volume ls -qf dangling=true)
    

    After :

    > docker info
    Metadata file: 
    Data Space Used: 1.43 GB
    Data Space Total: 53.39 GB
    Data Space Available: 51.96 GB
    Metadata Space Used: 577.5 kB
    Metadata Space Total: 54.53 MB
    Metadata Space Available: 53.95 MB
    
    0 讨论(0)
  • 2020-12-12 11:52

    I had a similar problem and I think this happens when you don't have enough space in the disk for all your docker images. I had 6GB reserved for docker images which it turned out not to be enough in my case. Anyway, I had removed every image and container and still disk looked full. Most of the space was being used by /var/lib/docker/devicemapper and /var/lib/docker/tmp.

    This command didn't work for me:

    # docker ps -qa | xargs docker inspect --format='{{ .State.Pid }}' | xargs -IZ fstrim /proc/Z/root/
    

    First, I stopped docker service:

    sudo service docker stop
    

    Then I deleted /var/lib/docker:

    Then I did what somebody suggested here in https://github.com/docker/docker/issues/18867#issuecomment-232301073

    • Remove existing instance of docker metadata rm -rf /var/lib/docker

      sudo rm -rf /var/lib/docker

    • Pass following options to docker daemon: -s devicemapper --storage-opt dm.fs=xfs --storage-opt dm.mountopt=discard

    • Start docker daemon.

    For last two steps, I run:

    sudo dockerd -s devicemapper --storage-opt dm.fs=xfs --storage-opt dm.mountopt=discard
    
    0 讨论(0)
  • 2020-12-12 11:54

    Had the same problem. In my scenario my vbox was running out of storage space. After an investigation found out that my docker local volumes were eating up 30gb. Ubuntu 16.04 host.

    To find out yours.

    docker system df
    
    TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
    Images              3                   0                   1.361GB             1.361GB (100%)
    Containers          0                   0                   0B                  0B
    Local Volumes       7                   0                   9.413GB             9.413GB (100%)
    Build Cache                                                 0B                  0B
    
    
    
    docker system prune --volumes
    
    
      WARNING! This will remove:
            - all stopped containers
            - all networks not used by at least one container
            - all volumes not used by at least one container
            - all dangling images
            - all build cache
    Are you sure you want to continue? [y/N]
    

    This frees up disk space of not used local volumes. At my scenario freed 20 GB of storage space. Make sure that containers which you want to keep are running before doing this if you want to keep them since this removes all stopped containers.

    0 讨论(0)
  • 2020-12-12 11:56

    maybe you can try docker system prune to remove all the images that are not important

    0 讨论(0)
  • 2020-12-12 11:58

    Docker prune by default does not remove volumes,

    you can try something like

    docker volume prune -f
    
    0 讨论(0)
  • 2020-12-12 11:59

    Move the /var/lib/docker directory.

    Assuming the /data directory has enough room, if not, substitute for one that does,

    sudo systemctl stop docker
    
    sudo mv /var/lib/docker /data
    
    
    sudo ln -s /data/docker /var/lib/docker
    
    sudo systemctl start docker
    

    This way, you don't have to reconfigure docker.

    0 讨论(0)
提交回复
热议问题