Ubuntu18.04 Docker中如何使能mount指令
最近在使用Docker部署自动化编译测试项目,过程中发现在Docker内不能使用mount指令挂载文件系统,错误如下图:

经过网上查资料及自己的亲身测试,找到如下两种方法
1.在执行docker run时添加--privileged=true参数,如下图:

2.使用docker-compose启动docker时在docker-compose.yml内添加privileged:true字段,如下图:

接着就可以正常使用mount指令挂载文件系统,并使用umount指令卸载文件系统了
原因是Docker为了更好的隔离性、安全性,不提供访问/dev/loop设备的权限,加上privileged参数后即可