站点图标 谷姐靓号网

Docker在已创建的container上挂载新目录

Rate this post

想把新硬盘挂载到docker上作为qbittorrent下载目录,结果搜了一遍要么说只能新建一个container,要么就是用啥hack方法麻烦得很,找到一个简单方法:

1. 停掉doker服务,用命令或者界面(群晖直接在界面关掉docker应用)
debian/ubuntu可以用命令

systemctl stop docker.service

2. 编辑特定container的配置文件,例如

vim /volume1/@docker/containers/0eb83a1f7d58ed1c801ac6cb6e14dbe54469ca434ca6e709270bb09ac8300273/config.v2.json

如果想将本机的/home/newfolder挂载docker的/mnt目录,则给MountPoints新增一个:

"MountPoints":{"/mnt":{"Source":"/home/newfolder","Destination":"/mnt","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/home/newfolder","Target":"/mnt"},"SkipMountpointCreation":false}}

3. 开启docker服务,群晖可以直接在图形界面点开始

4. 这时候如果还没法写入,可以给挂载的目录赋予更高的读写权限(比如777)

sudo chmod -R 777 /home/newfolder
退出移动版