The problem is that sudo
in your case does not change anything. It is not the ultimate solution for "Permission denied" kind of issues. This especially does not work when your container already runs on behalf of root
.
Privileged actions in Linux are governed by capabilities, which represent permissions for specific privileged operations. To keep this model compatible with classic UNIX model the processes running on behalf of root
by default have all capabilities. For example, things like sudo
, which escalate your UID to 0
, also grant you a full set of capabilities.
However, this is not true in containers — the amount of capabilities being available to the process in the container (even root
-owned) is limited by so-called bounding set, which by default contains very limited amount of capabilities, when running in Docker:
$ docker run -it ubuntu:14.04
root@fe50edf72783:/# capsh --print
Current: = cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,
cap_setuid,cap_setpcap,cap_net_bind_service,cap_net_raw,cap_sys_chroot,
cap_mknod,cap_audit_write,cap_setfcap+eip
Bounding set =cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,
cap_setuid,cap_setpcap,cap_net_bind_service,cap_net_raw,cap_sys_chroot,
cap_mknod,cap_audit_write,cap_setfcap
Network administration (interfaces configuration, etc.) requires CAP_NET_ADMIN
capability. As you see, it is not in the default bounding set of Docker containers, so you need to add it explicitly using --cap-add=net_admin
:
docker run -it --device=/dev/net/tun --cap-add=net_admin
After this, you will have this capability in the container. Considering that you run it on behalf of root
, having this capability makes using sudo
useless (it will not grant you more capabilities than now), so you may drop it and run OpenVPN simply with openvpn config.ovpn
.