docker with sshfs mounted directory

来源:互联网 发布:ue4 unity3d 编辑:程序博客网 时间:2024/06/03 21:30

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