docker 移動 data-root 到其他資料夾

起因

步驟

  1. 停止 docker service

    sudo systemctl stop docker
  2. 檢查原有設定、複製檔案

    cat /etc/docker/daemon.json
    sudo rsync -azAHX /var/lib/docker /volume/docker-dataroot
  3. 更換設定路徑

    option 1 modify docker config

    vi  /etc/docker/daemon.json
    {
      "data-root": "/volume/docker-dataroot"
    }

    *option 2 soft link folder**

    sudo mv /var/lib/docker /path-you-want-to-backup
    ln -s /volume/docker-dataroot/var/lib/docker
  4. 重啟 docker service

    sudo systemctl start docker

Reference

https://stackoverflow.com/questions/52488300/how-to-change-root-dir-of-docker-on-ubuntu-18-04-lts-docker-change-location-of