1

Because there are some good comments on this question I thought that they could be good answers and beneficial, in this particular question.

Therefore in order to be able to be more beneficial for the community, I thought to be able to get answered here.

In my gnu/linux system I have the /var as big as 20G but due to use with docker and the development of custom docker images the /var takes the 90% of the space so how can I same some space in /var?

I originally thought to do some backup as this question says, then repartition the /var. But seems too laborious to me. Is there a safer and less time-consuming alternative?

Dimitrios Desyllas
  • 979
  • 3
  • 11
  • 27

2 Answers2

4

If you have not done so for a while, then run docker system prune. It will run the garbage collector, and free a lot of disk space.

Note it may cause more work to be done next time you do something (such as build, pull, …), but should not remove anything that can not be got back.

ctrl-alt-delor
  • 27,473
  • 9
  • 58
  • 102
1

An alternative approach is to rsync the folder /var/lib/docker into a larger disk/partition. In my case, the partitions that contain /home/ has some heaps of free space; therefore I followed these steps:

  1. I made a dedicated folder in /home/ named docker

    mkdir /home/docker
    
  2. Using rsync, I copied the data to /home/docker

    rsync -av /var/lib/docker/ /home/docker
    

    This makes /home/docker an exact copy of /var/lib/docker. Note that the trailing slash on the source directory is deliberate. Without it, you would get a docker directory inside /home/docker.

  3. I checked how the rsync process went:

    ls -l /home/docker
    
  4. I terminated the docker daemon: (I'm using Ubuntu; therefore, using service was working fine, also using systemctl will do the job in most distros)

    sudo service docker stop
    
  5. Remove the /var/lib/docker

    rm -rf /var/lib/docker
    
  6. Symlink into /home/docker

    sudo ln -s /home/docker /var/lib/docker
    
  7. Start docker once again:

    sudo service docker start
    
Kusalananda
  • 320,670
  • 36
  • 633
  • 936
Dimitrios Desyllas
  • 979
  • 3
  • 11
  • 27