首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >无法在Docker中挂载文件

无法在Docker中挂载文件
EN

Stack Overflow用户
提问于 2018-05-28 22:02:12
回答 1查看 2.8K关注 0票数 4

错误描述

我无法在Vagrant或Docker中挂载文件,所以这似乎是由某种权限错误引起的问题。

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

与Vagrant相关的错误讨论可以在另一个问题中找到:Unable to mount files in Vagrant

Docker故障排除

我无法使用docker-compose将文件挂载到Docker容器中,我正在尝试构建:https://github.com/fredrikaverpil/saltstack-docker

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

代码语言:javascript
复制
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 up时得到了以下输出

代码语言:javascript
复制
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 inspect命令会显示正确的配置:

代码语言:javascript
复制
   "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"
        }

但是进入容器(使用另一个入口点命令),会显示应该挂载的文件丢失:

代码语言:javascript
复制
[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

结论

当涉及到复制文件时,我的本地计算机上似乎出现了一些非常混乱的情况,可能与我的用户如何配置以及它有权将文件挂载到虚拟机和容器中有关。

如果有人能对此有所了解,我将不胜感激。

更新

更新1

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

代码语言:javascript
复制
> 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似乎帮助了一些用户,但我不认为这是安全的。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50568151

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档