linux挂载docker中的文件,无法在Docker中挂载文件

错误说明

我无法在Vagrant或Docker中挂载文件,因此看起来这是由某种权限错误引起的问题.

我的操作系统是Ubuntu 18.04 LTS(Bionic Beaver),据我所知,我没有像SELinux那样运行任何访问控制模块.

Docker故障排除

我将docker-compose文件中的卷设置为:

volumes:

- ${PWD}/assets/master/etc/supervisor:/etc/supervisor

- ${PWD}/assets/master/etc/salt:/etc/salt

- ${PWD}/assets/master/var/cache/salt:/var/cache/salt

- ${PWD}/assets/master/var/log/salt:/var/log/salt

- ${PWD}/assets/master/srv:/srv

然而,当我运行docker-compose时,我得到了这个输出:

Creating network "saltstack_default" with the default driver

Creating salt_image

Creating salt

Creating minion

Attaching to salt, minion, salt_image

salt | Error: could not find config file /etc/supervisor/supervisord.conf

salt | For help, use /usr/bin/supervisord -h

salt exited with code 2

salt_image exited with code 0

minion | [ERROR ] DNS lookup of 'salt' failed.

minion | [ERROR ] Master hostname: 'salt' not found. Retrying in 30 seconds

docker检查容器显示正确的配置:

"Mounts": [

{

"Type": "bind",

"Source": "/somedir/saltstack/assets/master/etc/salt",

"Destination": "/etc/salt",

"Mode": "rw",

"RW": true,

"Propagation": "rprivate"

},

{

"Type": "bind",

"Source": "/somedir/saltstack/assets/master/var/cache/salt",

"Destination": "/var/cache/salt",

"Mode": "rw",

"RW": true,

"Propagation": "rprivate"

},

{

"Type": "bind",

"Source": "/somedir/saltstack/assets/master/etc/supervisor",

"Destination": "/etc/supervisor",

"Mode": "rw",

"RW": true,

"Propagation": "rprivate"

},

{

"Type": "bind",

"Source": "/somedir/saltstack/assets/master/var/log/salt",

"Destination": "/var/log/salt",

"Mode": "rw",

"RW": true,

"Propagation": "rprivate"

},

{

"Type": "bind",

"Source": "/somedir/saltstack/assets/master/srv",

"Destination": "/srv",

"Mode": "rw",

"RW": true,

"Propagation": "rprivate"

}

但是输入容器(使用另一个入口点命令)会显示缺少应该挂载的文件:

[root@salt /]# ll /etc/supervisor

total 0

[root@salt /]# ll /etc/salt

total 0

[root@salt /]# ll /var/cache/salt

total 0

[root@salt /]# ll /var/log/salt

total 0

[root@salt /]# ll /srv

total 0

结论

在复制文件时,我的本地机器似乎有些混乱,可能与我的用户配置方式以及将文件挂载到VM和容器有什么访问权限有关.

如果有人能对此有所了解,我会很感激.

更新

更新1

我怀疑这是一个与/ var / lib / docker中的旧东西的问题,我即将删除,但在此之前这是我得到的另一个错误,可能是某种权限错误:

> cat docker-compose.yml

# based on https://docs.docker.com/samples/library/nginx/#using-environment-variables-in-nginx-configuration

version: '2'

services:

web:

image: nginx

volumes:

- ./testfile.txt:/etc/nginx/

ports:

- "8080:80"

environment:

- NGINX_HOST=foobar.com

- NGINX_PORT=80

command: /bin/bash -c "nginx -g 'daemon off;'"

> docker-compose up

Creating network "docker_compose-mounting_issue_default" with the default driver

Creating docker_compose-mounting_issue_web_1 ... error

ERROR: for docker_compose-mounting_issue_web_1 Cannot start service web: b'OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"rootfs_linux.go:58: mounting \\\"/home/.../troubleshoot/docker_compose-mounting_issue/testfile.txt\\\" to rootfs \\\"/var/lib/docker/aufs/mnt/580b79241399e838c67b74021ecf2597aade5f1711811f4ab5c9c7bbcd188449\\\" at \\\"/var/lib/docker/aufs/mnt/580b79241399e838c67b74021ecf2597aade5f1711811f4ab5c9c7bbcd188449/etc/nginx\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type'

ERROR: for web Cannot start service web: b'OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"rootfs_linux.go:58: mounting \\\"/home/.../troubleshoot/docker_compose-mounting_issue/testfile.txt\\\" to rootfs \\\"/var/lib/docker/aufs/mnt/580b79241399e838c67b74021ecf2597aade5f1711811f4ab5c9c7bbcd188449\\\" at \\\"/var/lib/docker/aufs/mnt/580b79241399e838c67b74021ecf2597aade5f1711811f4ab5c9c7bbcd188449/etc/nginx\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type'

ERROR: Encountered errors while bringing up the project.

更新2

所以我删除了/ var / lib / docker /中的所有内容,它现在可以正常工作,挂载我的文件.它可能在某个地方被打破了.我遇到的另一个建议是给目录权限,chmod 777似乎可以帮助一些用户,但我不认为这是安全的..

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值