---
title: "Move Docker data-root"
date: 2020-11-22T22:42:14.000Z
author: Z.SHINCHVEN
tags: [Docker, docker daemon]
canonical: https://atlassc.net/2020/11/23/move-docker-data-root
---
Do you ever feel files in `/var/lib/docker` are taking so much space of your system partition's storage? That's because the directory is storing docker's images and containers' file-systems, and we all know that those things are really big.

Fortunately, you can actually move docker's `data-root` to another path by configuring `/etc/docker/daemon.json`[daemon configuration file](https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file).

## WARING: if you are migrating an existing docker data root

Some existing containers may encounter error after migration, you must:

- Make sure that everything you want to save has been backed up or persisted out of the container(on host) by [mirroring data volumes](https://docs.docker.com/storage/volumes/). 
- Make sure all containers can be recreated.

It is a good practice to always persist data out of docker container, all containers and images should be seemed as app binaries.

## Before You Start

You should stop the docker daemon:

```bash
systemctl stop docker
```

## Copy Existing

It is recommended to copy everything instead of moving them, so that you can still find a way back when error occurred.

```bash
cp -r /var/lib/docker /path/to/docker/data/root
```

## data-root Configuration

By adding or modifying `data-root` in `/etc/docker/daemon.json`, the [configuration](https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file) is done.

```json
{
    "data-root": "/path/to/docker/data/root"
}
```

## Restart

```bash
systemctl start docker
```
