{"id":72,"date":"2018-01-25T10:16:17","date_gmt":"2018-01-24T22:16:17","guid":{"rendered":"https:\/\/adriel.co.nz\/blog\/?p=72"},"modified":"2018-01-28T19:51:44","modified_gmt":"2018-01-28T07:51:44","slug":"change-docker-data-directory-in-debian-jessie","status":"publish","type":"post","link":"https:\/\/blog.adriel.co.nz\/2018\/01\/25\/change-docker-data-directory-in-debian-jessie\/","title":{"rendered":"Change Docker data directory on Debian"},"content":{"rendered":"

If you’ve installed Docker with the default settings on Debian, it will be storing Docker images, containers and volumes in \/var\/lib\/docker<\/code><\/span>, which will be an issue if you have \/var<\/code><\/span> on its own (usually small) partition.<\/span><\/p>\n

After using Docker for a while you may start to run out of space on the \/var partition, at which point you’ll need to either add more space to that partition or relocate it to somewhere with more space.<\/p>\n

Here are the steps to change the directory even after you’ve created Docker containers etc.
\n<\/span><\/strong>Note, you don’t need to edit docker.service<\/code><\/span>\u00a0or init.d files, as it will read the change from the .json<\/code><\/span> file mentioned below.<\/span><\/p>\n

Steps<\/span><\/h4>\n
    \n
  1. Edit \/etc\/docker\/daemon.json<\/code><\/span> (if it doesn’t exist, create it)<\/em><\/span><\/span><\/li>\n
  2. Add the following<\/span>\n
    {\r\n  \"data-root\"<\/span>: \"\/new\/path\/to\/docker-data\"<\/span>\r\n}<\/pre>\n<\/li>\n
  3. Stop docker<\/span>\n
    sudo<\/span> systemctl stop<\/span> docker<\/pre>\n<\/li>\n
  4. Check docker has been stopped<\/span>\n
    ps<\/span> aux | grep<\/span> -i<\/span> docker | grep<\/span> -v<\/span> grep<\/span><\/pre>\n<\/li>\n
  5. Copy the files to the new location
    \n<\/span>Optionally you could run this inside screen<\/code><\/span><\/a> if you have a large amount of data or unreliable ssh connection.<\/em><\/span><\/span><\/p>\n
    sudo<\/span> rsync -axPS<\/span> \/var\/lib\/docker\/ \/new\/path\/to\/docker-data<\/pre>\n

    Options explanation<\/strong><\/span>, check out the man page for more info<\/a><\/span><\/p>\n

    -a<\/span>, --archive<\/span> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 archive mode; equals -rlptgoD<\/span> (no -H<\/span>,-A,-X)<\/pre>\n
    -x<\/span>, --one-file-system<\/span> \u00a0 \u00a0 don't cross filesystem boundaries<\/span><\/pre>\n
    -P<\/span> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  show progress during transfer<\/pre>\n
    -S<\/span>, --sparse<\/span> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  handle sparse files efficiently<\/pre>\n<\/li>\n
  6. Start Docker back up<\/span>\n
    sudo<\/span> systemctl start<\/span> docker<\/pre>\n<\/li>\n
  7. Check Docker has started up using the new location<\/span>\n
    docker info | grep<\/span> 'Docker Root Dir'<\/span><\/pre>\n<\/li>\n
  8. Check everything has started up that should be running<\/span>\n
    docker ps<\/span><\/pre>\n<\/li>\n<\/ol>\n

    Leave both<\/strong><\/span> copies on the server for a few days to make sure no issues arise, then feel free to delete it.<\/span><\/span><\/p>\n

    sudo<\/span> rm<\/span> -r<\/span> \/var\/lib\/docker<\/pre>\n

    <\/h3>\n

    Documentation \/ sources<\/h3>\n

    Official docs <\/span>https:\/\/docs.docker.com\/engine\/admin\/systemd\/<\/a><\/span><\/span><\/p>\n

    Docker GitHub issue item https:\/\/github.com\/docker\/docker\/issues\/3127<\/a><\/span><\/span><\/p>\n

    Blog post inspired by\u00a0linuxconfig<\/a><\/span><\/p>\n

    Tested and working on Debian Stretch (9.3) with Docker Docker version 17.12.0-ce<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"

    If you’ve installed Docker with the default settings on Debian, it will be storing Docker images, containers and volumes in \/var\/lib\/docker, which will be an issue if you have \/var on its own (usually small) partition. After using Docker for a while you may start to run out of space on the \/var partition, at […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,2],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.adriel.co.nz\/wp-json\/wp\/v2\/posts\/72"}],"collection":[{"href":"https:\/\/blog.adriel.co.nz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.adriel.co.nz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.adriel.co.nz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.adriel.co.nz\/wp-json\/wp\/v2\/comments?post=72"}],"version-history":[{"count":10,"href":"https:\/\/blog.adriel.co.nz\/wp-json\/wp\/v2\/posts\/72\/revisions"}],"predecessor-version":[{"id":191,"href":"https:\/\/blog.adriel.co.nz\/wp-json\/wp\/v2\/posts\/72\/revisions\/191"}],"wp:attachment":[{"href":"https:\/\/blog.adriel.co.nz\/wp-json\/wp\/v2\/media?parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.adriel.co.nz\/wp-json\/wp\/v2\/categories?post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.adriel.co.nz\/wp-json\/wp\/v2\/tags?post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}