docker工作目录mount到其他目录

Below is one common approach using a bind mount to move Docker’s data directory to your /usr/g filesystem:

  1. Stop Docker to avoid any corruption while moving data:

bash

sudo systemctl stop docker

  1. Create a new directory on /usr/g for Docker data (if not already available):

bash

sudo mkdir -p /usr/g/docker

  1. Move the current Docker data from /var/lib/docker to the new location:

bash

sudo mv /var/lib/docker/* /usr/g/docker/

  1. Back up the original /var/lib/docker directory (optional):

bash

sudo mv /var/lib/docker /var/lib/docker.bak

Then recreate an empty directory for the mount point:

bash

sudo mkdir /var/lib/docker

  1. Mount the new directory as a bind mount to /var/lib/docker:

bash

sudo mount --bind /usr/g/docker /var/lib/docker

  1. To make this change permanent across reboots, add a bind mount entry to your /etc/fstab. Open /etc/fstab with your favorite editor, for example:

bash

sudo nano /etc/fstab

Then add the following line:

/usr/g/docker  /var/lib/docker  none  bind  0  0

  1. Start Docker:

bash

sudo systemctl start docker

  1. Verify that Docker is using the new storage location by checking Docker info:

bash

sudo docker info | grep "Docker Root Dir"

This setup moves Docker’s data directory to a partition that has more available space on /usr/g while keeping the original path (/var/lib/docker) for Docker to use.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值