Search code examples
dockervagrantvagrantfilevagrant-provision

How can I use another directory to save built Docker containers?


I am using Vagrant with Docker provision.

The issue is when I run my docker compose I fill up my VM disk space.

Here is what my file system looks like:

Filesystem      Size  Used Avail Use% Mounted on
udev            476M     0  476M   0% /dev
tmpfs            97M  3.1M   94M   4% /run
/dev/sda1       9.7G  2.2G  7.5G  23% /
tmpfs           483M     0  483M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           483M     0  483M   0% /sys/fs/cgroup
tmpfs            97M     0   97M   0% /run/user/1000
vagrant_        384G   39G  345G  11% /vagrant
vagrant_www_    384G   39G  345G  11% /vagrant/www

How can I configure Docker or Vagrant to use /vagrant directory?

(By the way I have not loaded Docker... This is why it's not 100% disk usage)


Solution

  • You can try to reconfigure the Docker daemon as documented here -> https://docs.docker.com/engine/reference/commandline/dockerd/#options. Use the -g parameter to change the root runtime path of the Docker daemon.

    --graph, -g /var/lib/docker Root of the Docker runtime
    

    As long as you are working on a local disk or SAN this would be a proper way to change the location of the Docker data including the images. But be aware, do not use NFS or another type of share because this won't work as of the used massive file locks. Somewhere on Github there is an issue about this.