{"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 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. Options explanation<\/strong><\/span>, check out the man page for more info<\/a><\/span><\/p>\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 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\/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
\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
\/etc\/docker\/daemon.json<\/code><\/span> (if it doesn’t exist, create it)<\/em><\/span><\/span><\/li>\n
{\r\n \"data-root\"<\/span>: \"\/new\/path\/to\/docker-data\"<\/span>\r\n}<\/pre>\n<\/li>\n
sudo<\/span> systemctl stop<\/span> docker<\/pre>\n<\/li>\n
ps<\/span> aux | grep<\/span> -i<\/span> docker | grep<\/span> -v<\/span> grep<\/span><\/pre>\n<\/li>\n
\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
-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
sudo<\/span> systemctl start<\/span> docker<\/pre>\n<\/li>\n
docker info | grep<\/span> 'Docker Root Dir'<\/span><\/pre>\n<\/li>\n
docker ps<\/span><\/pre>\n<\/li>\n<\/ol>\n
sudo<\/span> rm<\/span> -r<\/span> \/var\/lib\/docker<\/pre>\n
<\/h3>\n
Documentation \/ sources<\/h3>\n