You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
After capabilities have been introduced, I thought it is now possible to mount external folders (from the host or remote machine with SSHFS) inside running containers without use of --privileged. Am I wrong?
I run Docker 1.3.1 and I cannot mount without --privileged.
Here is a similar issue: #6535
Are you on a system like ubuntu that has apparmor? This could be apparmor blocking the mount, you can look in dmesg and you should see the apparmor blocking this call.
My host has Ubuntu 12.04.
I put apparmor docker-default profile into complain mode:
peter@poweredge320:~$ sudo apparmor_status
apparmor module is loaded.
9 profiles are loaded.
8 profiles are in enforce mode.
/sbin/dhclient
/usr/bin/lxc-start
/usr/lib/NetworkManager/nm-dhcp-client.action
/usr/lib/connman/scripts/dhclient-script
/usr/sbin/named
/usr/sbin/ntpd
/usr/sbin/tcpdump
lxc-container-default
1 profiles are in complain mode.
docker-default
3 processes have profiles defined.
2 processes are in enforce mode.
/usr/sbin/named (1359)
/usr/sbin/ntpd (1155)
1 processes are in complain mode.
docker-default (16864)
0 processes are unconfined but have a profile defined.
But still when I start container with --cap-add SYS_ADMIN I cannot use sshfs:
root@e76cafc2dc34:/# sshfs peter@172.17.42.1:/home/peter/ /mnt
fuse: failed to open /dev/fuse: Operation not permitted
By the way, without --cap-add SYS_ADMIN the error message is different (was "fuse: failed to open /dev/fuse: Operation not permitted" before):
11:36:26peter@poweredge320:~$ docker run -ti --name dev --device /dev/fuse peter/dev:sshfs /bin/bash
root@1d49112eaf95:/# sshfs peter@172.17.42.1:/home/peter/ /mnt
fusermount: mount failed: Permission denied
Thank you all for your help!
The final answer:
Use --cap-add SYS_ADMIN --device /dev/fuse to mount folders with sshfs in container.
Reacted by Carl Ambroselli, tobe, Andras Tim, Daniel Lamando, Benjamin Hughes, Jon Wu, John-Philip Johansson, frosetti, Jianxin,Ren and Jonathan Chemla
Reacted by DK
Reacted by Arockiasamy K, vito.he and Fabian Peter Hammerle
Do you happen to know how I can start an already existing container with those flags?
I tried using "docker start container_name --privileged --cap-add=MKNOD --cap-add=SYS_ADMIN --device=/dev/fuse" but I'm unable to use those flags with the start command.
With the docker run command it creates a new container that I then have to re-setup.
@Rick7C2 you can't, you need to start a new container with those options. Depending on your use case, you can start a privileged session in an existing container through docker exec -it --privileged <container> bash
The comments about seccomp:unconfined above might be out of date. As mentioned in #16429 you need apparmor:unconfined to mount fuse volumes in a container. You should not need to use --privileged.
I'm new to Docker so it's possible some of the args are redundant, except --priviledged, it doesn't work without it in docker run. Also followed instructions here, not sure if that's relevant or not.
@sarpk no; a container / image itself should not be able to gain privileges by itself; that would really be dangerous because simply running that image would give it root access to your host; and basically remove all the isolation / security that containers bring. Giving privileges needs to be an explicit action, that you set at runtime (on docker run)
Any idea how to do this without the dangerous CAP_SYS_ADMIN?
I've tried explicitly defining a policy, and putting mount/umount/umount2 in the allowed calls, but it still doesn't work unless I --cap-add=SYS_ADMIN. Strace says the mount() call is getting EPERM :(
Reacted by Ahmed ElSayed, Ryo Okubo, Evan Ye and Omeid Matten
Activity
cpuguy83 commentedon Dec 2, 2014
Mount requires CAP_SYS_ADMIN, which is not allowed in the default container.
You should be able to do this with "docker run --cap-add SYS_ADMIN
SvenDowideit commentedon Dec 3, 2014
this comes up often enough that we should add an example to the docs.
pyotr777 commentedon Dec 3, 2014
Thank you for your answers!
I still get error when trying to mount host folder with sshfs.
Inside container started with --cap-add SYS_ADMIN:
With --privileged it works.
crosbymichael commentedon Dec 3, 2014
Are you on a system like ubuntu that has apparmor? This could be apparmor blocking the mount, you can look in
dmesgand you should see the apparmor blocking this call.pyotr777 commentedon Dec 4, 2014
My host has Ubuntu 12.04.
I put apparmor docker-default profile into complain mode:
But still when I start container with --cap-add SYS_ADMIN I cannot use sshfs:
In dmesg I see lots of messages like this:
When docker-default was in enforce mode, I didn't see docker-related messages in dmesg.
In container started with --privileged I can mount host folders with sshfs.
tianon commentedon Dec 4, 2014
You should try adding
--device /dev/fuse, too.pyotr777 commentedon Dec 4, 2014
Thank you, Tianon!
Added
--device /dev/fuseand voilà:By the way, without --cap-add SYS_ADMIN the error message is different (was "fuse: failed to open /dev/fuse: Operation not permitted" before):
Thank you all for your help!
The final answer:
Use
--cap-add SYS_ADMIN --device /dev/fuseto mount folders with sshfs in container.jessfraz commentedon Dec 4, 2014
Going to close this then, glad everything is working :)
SvenDowideit commentedon Dec 4, 2014
reopening as it really needs docs.
crosbymichael commentedon Dec 4, 2014
Assigning to @SvenDowideit so hopefully this does not sit open for a long long time.
18 remaining items
hairyhenderson commentedon Feb 3, 2016
My bad - my client was v1.9.1. When I flipped back to v1.10 it works just fine. Thank you! 😁
Rick7C2 commentedon Apr 24, 2016
Do you happen to know how I can start an already existing container with those flags?
I tried using "docker start container_name --privileged --cap-add=MKNOD --cap-add=SYS_ADMIN --device=/dev/fuse" but I'm unable to use those flags with the start command.
With the docker run command it creates a new container that I then have to re-setup.
thaJeztah commentedon Apr 24, 2016
@Rick7C2 you can't, you need to start a new container with those options. Depending on your use case, you can start a privileged session in an existing container through
docker exec -it --privileged <container> bashjamshid commentedon May 24, 2016
The comments about seccomp:unconfined above might be out of date. As mentioned in #16429 you need
apparmor:unconfinedto mount fuse volumes in a container. You should not need to use--privileged.sent-hil commentedon May 29, 2016
Was able to get it working with:
and
ubuntu-fuse is based off phusion/baseimage-docker
I'm new to Docker so it's possible some of the args are redundant, except
--priviledged, it doesn't work without it indocker run. Also followed instructions here, not sure if that's relevant or not.sarpk commentedon Sep 25, 2016
Sorry to open this again, is it not possible to add these to Dockerfile so that we can prevent writing each time we are running it?
thaJeztah commentedon Sep 25, 2016
@sarpk no; a container / image itself should not be able to gain privileges by itself; that would really be dangerous because simply running that image would give it root access to your host; and basically remove all the isolation / security that containers bring. Giving privileges needs to be an explicit action, that you set at runtime (on
docker run)tobegit3hub commentedon Mar 29, 2017
--cap-add SYS_ADMIN --device=/dev/fuse --security-opt apparmor:unconfinedworks for me without--privilegedin Ubuntu.ZongqiangZhang commentedon May 17, 2017
docker run -it --cap-add MKNOD --cap-add SYS_ADMIN --device /dev/fuseworks for centos 7.0 with Docker 17.05.0-ceOn ubuntu 16.04, I needed to disable apparmor to use fuse
Disable apparmor to use fuse
manos commentedon Mar 9, 2018
Any idea how to do this without the dangerous CAP_SYS_ADMIN?
I've tried explicitly defining a policy, and putting mount/umount/umount2 in the allowed calls, but it still doesn't work unless I --cap-add=SYS_ADMIN. Strace says the mount() call is getting EPERM :(
omeid commentedon Jul 18, 2019
Being able to use fuse without SYS_ADMIN would be very helpful, this is needed for running AppImages inside docker.
klzsysy commentedon May 16, 2020
--security-opt="seccomp=unconfined"kernel mount--cap-add=SYS_ADMINkernel and fuse--device /dev/fusefuse mountuse kernel module mount cephfs
with fuse mount also is very good