TopHome
<2022-03-01 Tue>containers

Re-homing Docker Data directory

1. Why?

By default Docker data is stored in `/var/lib/docker`, ie mounted as a part of `/`. However, `/` may not have enough space to to hold all your Docker images, forget volumes or running software like Kind. Let's change this.

This guide is based on: https://www.digitalocean.com/community/questions/how-to-move-the-default-var-lib-docker-to-another-directory-for-docker-on-linux

2. Pick your new directory

Let's create a folder to hold the `docker` related stuff on a mount that has lot of space. For this example, say `/home`. Create `/home/docker`.

3. Stop Docker

``` sudo systemctl stop docker ```

4. Copy over the existing files

``` sudo cp -axT /var/lib/docker /home/docker/data ``` This may take some time.

5. Edit the Docker config file

Edit your `/etc/docker/daemon.json` file to include the following line: ``` "graph": "/home/docker/data" ``` Note the key used here: "graph". In newer versions of Docker, you need "data-root". You can verify this by seeing which of the 2 flags is available under `dockerd help`.

6. Restart Docker Daemon

``` sudo systemctl start docker ```

That's it. Docker should start up and work well.