docker with sshfs mounted directory

requirement

I want to run a docker image in machine A, and mount a directory DIR_B in Machine B.

try

I mkdir a directory DIR_A in machine A, and used sshfs to mount the dir in machine B:

mkdir -p DIR_A
sshfs DIR_IP:DIR_B DIR_A

then mount the dir in docker container:

docker run -it –rm -v=”DIR_A:DIR_IN_DOCKER” DOCKER_IMAGE /bin/bash

But the docker daemon reported an error and exited.

So I changed DIR_A to it’s parent directory, and run again:

docker run -it –rm -v=”DIR_A:DIR_IN_DOCKER” DOCKER_IMAGE /bin/bash
$ ls

This time, the docker can be started, and “ls” reports another error “permission denied”
So this should be a file permission issue.

solution

Checked sshfs manual, and found out these lines:

FUSE options:

-o allow_other
allow access to other users

So this should be caused by the docker container is executed by the docker daemon, and the UID of docker daemon is not the same as the current user.
So use the following command to update fuse config:

echo ‘user_allow_other’ | sudo tee -a /etc/fuse.conf
sudo chmod 644 /etc/fuse.conf

Then mount with:

sshfs -o allow_other,uid=1000,gid=1000 DIR_IP:DIR_B DIR_A

note: uid and gid should be the same as the uid & gid inside the docker container.

Then run docker:

docker run -it –rm -v=”DIR_A:DIR_IN_DOCKER” DOCKER_IMAGE /bin/bash

Success.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值