Docker Volume 没有挂载任何文件 [英] Docker Volume not mounting any files

查看:14
本文介绍了Docker Volume 没有挂载任何文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的源文件挂载到位于/var/dynamo 的 docker 目录中.我希望能够在本地运行 Docker 并在工作时使用我的本地文件.

使用运行命令:

docker run -v $(pwd):/var/dynamo -d -t -p 8001:8001 --name dynamo davesrepo/dynamo

使用我的Dockerfile

FROM python:3.5.1工作目录/var/dynamo运行 pip3 安装龙卷风曝光 8001

但是,当我 bash 进入容器 docker exec -it dynamo/bin/bash 并运行 ls -la 时,目录 是空的!

root@7d3d338891aa:/var/dynamo# ls -la共 4 个drwxr-xr-x 2 根根 40 Dec 29 03:37 .drwxr-xr-x 24 根 4096 12 月 29 日 03:36 ..

运行 docker inspect dynamo 显示正确挂载的目录

<预><代码>[{"Id": "7d3d338891aae32e001a3bb31d6be17802d238526830396472b011599a97212a","创建": "2015-12-29T03:37:01.416445958Z","路径": "python3","参数": [],状态": {"状态": "运行",运行":真,暂停":假,重新启动":假,OOMKilled":假,死":假,PID":1314,退出代码":0,错误": "","StartedAt": "2015-12-29T03:37:01.516253705Z","FinishedAt": "0001-01-01T00:00:00Z"},"图片": "19697c9b5c7561b113d817821280971f063ea0187c82343c0832348fb6863c9a","ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/7d3d338891aae32e001a3bb31d6be17802d238526830396472b011599a97212a/resolv.conf","主机名路径": "/mnt/sda1/var/lib/docker/containers/7d3d338891aae32e001a3bb31d6be17802d238526830396472b011599a97212a/hostname","HostsPath": "/mnt/sda1/var/lib/docker/containers/7d3d338891aae32e001a3bb31d6be17802d238526830396472b011599a97212a/hosts",日志路径":/mnt/sda1/var/lib/docker/containers/7d3d338891aae32e001a3bb31d6be17802d238526830396472b011599a97212a/7d3d338891aae32e001a3bb31d6be17802d238526830396472b011599a97212a-json.log""名称": "/发电机",重启计数":0,"驱动程序": "aufs","ExecDriver": "native-0.2","MountLabel": "","进程标签": "","AppArmorProfile": "",ExecIDs":空,主机配置":{绑定":[/Users/dave/Sites/davesrepo/dynamo:/var/dynamo"],"ContainerIDFile": "","LxcConf": [],内存":0,"内存预留": 0,内存交换":0,"内核内存": 0,"CpuShares": 0,"CPUPeriod": 0,"CpusetCpus": "","CpusetMems": "","CPUQuota": 0,"BlkioWeight": 0,OomKillDisable":假,内存交换":-1,特权":假,端口绑定":{8001/tcp":[{"HostIp": "",主机端口":8001"}]},链接":空,PublishAllPorts":假,"DNS": [],"DnsOptions": [],"DnsSearch": [],额外主机":空,VolumesFrom":空,设备": [],"网络模式": "默认","IpcMode": "","PidMode": "","UTSMode": "",CapAdd":空,CapDrop":空,GroupAdd":空,重启策略":{"姓名": "没有",最大重试计数":0},SecurityOpt":空,ReadonlyRootfs":假,Ulimits":空,日志配置":{"类型": "json 文件",配置":{}},"CgroupParent": "",控制台大小":[0,0],音量驱动程序":"},图形驱动程序":{"名称": "aufs",数据":空},坐骑":[{"来源": "/Users/dave/Sites/davesrepo/dynamo","目的地": "/var/dynamo",模式": "",RW":真}],配置":{"主机名": "7d3d338891aa","域名": "","用户": "",AttachStdin":假,AttachStdout":假,AttachStderr":假,暴露端口":{8001/tcp":{}},Tty":真的,OpenStdin":假,StdinOnce":假,环境":["APP_ENV=开发","PYTHONPATH=$PYTHONPATH:/var/dynamo","PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","LANG=C.UTF-8","PYTHON_VERSION=3.5.1",PYTHON_PIP_VERSION=7.1.2"],命令":[蟒蛇3"],"图片": "davesrepo/发电机",卷":空,"WorkingDir": "/var/dynamo",入口点":空,OnBuild":空,标签": {},"StopSignal": "SIGTERM"},网络设置": {桥": "","沙箱ID": "71d99a7d11908a9d1c0156fd33eb3f0ff5ef9f6697bb77103fe2caa1cf488530",发夹模式":假,"LinkLocalIPv6Address": "","LinkLocalIPv6PrefixLen": 0,端口":{8001/tcp":[{"HostIp": "0.0.0.0",主机端口":8001"}]},"SandboxKey": "/var/run/docker/netns/71d99a7d1190","SecondaryIPAddresses": null,"SecondaryIPv6Addresses": null,"端点ID": "1cc99b0de89700368f31b43248c90ea45cec756712a2bd2ba2dc57293a5d0a72","网关": "172.17.0.1","GlobalIPv6Address": "","GlobalIPv6PrefixLen": 0,"IPAddress": "172.17.0.2","IPPrefixLen": 16,"IPv6Gateway": "","MacAddress": "02:42:ac:11:00:02",网络":{桥": {"端点ID": "1cc99b0de89700368f31b43248c90ea45cec756712a2bd2ba2dc57293a5d0a72","网关": "172.17.0.1","IPAddress": "172.17.0.2","IPPrefixLen": 16,"IPv6Gateway": "","GlobalIPv6Address": "","GlobalIPv6PrefixLen": 0,"MacAddress": "02:42:ac:11:00:02"}}}}]

Docker 版本为 1.9.1

解决方案

Docker &Virtualbox 似乎在将卷挂载到/Users 目录之外时遇到问题.解决此问题的唯一方法是删除 docker 机器映像,将/Users/yourname 目录正确设置为 Virtualbox 中的共享文件夹,然后创建一个新的 docker 机器映像.

解决问题的步骤:

  1. docker-machine stop dev
  2. docker-machine rm dev
  3. docker-machine create --driver virtualbox dev
  4. eval "$(docker-machine env dev)"
  5. docker build -t davesrepo/dynamo -f ./Dockerfile .
  6. docker run -v $(pwd):/var/dynamo -d -t -p 8001:8001 --env-file ./dynamo.env --name dynamo davesrepo/dynamo
  7. docker exec -it dynamo/bin/bash
  8. ls

root@42f9e47fa2de:/var/dynamo# lsDockerfile README.md __init__.py __pycache__ bin config.ini requirements.txt seed.sql 测试

文件!

I'm trying to mount my source files to a directory in docker located at /var/dynamo. I'd like to be able to run Docker locally and use my local files as I am working.

with the run command:

docker run -v $(pwd):/var/dynamo -d -t -p 8001:8001 --name dynamo davesrepo/dynamo

with my Dockerfile

FROM python:3.5.1
WORKDIR /var/dynamo
RUN pip3 install tornado
EXPOSE 8001

However, when I bash into the container docker exec -it dynamo /bin/bash and run ls -la the directory is empty!

root@7d3d338891aa:/var/dynamo# ls -la
total 4
drwxr-xr-x  2 root root   40 Dec 29 03:37 .
drwxr-xr-x 24 root root 4096 Dec 29 03:36 ..

Running docker inspect dynamo shows the directory mounted properly

[
{
    "Id": "7d3d338891aae32e001a3bb31d6be17802d238526830396472b011599a97212a",
    "Created": "2015-12-29T03:37:01.416445958Z",
    "Path": "python3",
    "Args": [],
    "State": {
        "Status": "running",
        "Running": true,
        "Paused": false,
        "Restarting": false,
        "OOMKilled": false,
        "Dead": false,
        "Pid": 1314,
        "ExitCode": 0,
        "Error": "",
        "StartedAt": "2015-12-29T03:37:01.516253705Z",
        "FinishedAt": "0001-01-01T00:00:00Z"
    },
    "Image": "19697c9b5c7561b113d817821280971f063ea0187c82343c0832348fb6863c9a",
    "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/7d3d338891aae32e001a3bb31d6be17802d238526830396472b011599a97212a/resolv.conf",
    "HostnamePath": "/mnt/sda1/var/lib/docker/containers/7d3d338891aae32e001a3bb31d6be17802d238526830396472b011599a97212a/hostname",
    "HostsPath": "/mnt/sda1/var/lib/docker/containers/7d3d338891aae32e001a3bb31d6be17802d238526830396472b011599a97212a/hosts",
    "LogPath": "/mnt/sda1/var/lib/docker/containers/7d3d338891aae32e001a3bb31d6be17802d238526830396472b011599a97212a/7d3d338891aae32e001a3bb31d6be17802d238526830396472b011599a97212a-json.log",
    "Name": "/dynamo",
    "RestartCount": 0,
    "Driver": "aufs",
    "ExecDriver": "native-0.2",
    "MountLabel": "",
    "ProcessLabel": "",
    "AppArmorProfile": "",
    "ExecIDs": null,
    "HostConfig": {
        "Binds": [
            "/Users/dave/Sites/davesrepo/dynamo:/var/dynamo"
        ],
        "ContainerIDFile": "",
        "LxcConf": [],
        "Memory": 0,
        "MemoryReservation": 0,
        "MemorySwap": 0,
        "KernelMemory": 0,
        "CpuShares": 0,
        "CpuPeriod": 0,
        "CpusetCpus": "",
        "CpusetMems": "",
        "CpuQuota": 0,
        "BlkioWeight": 0,
        "OomKillDisable": false,
        "MemorySwappiness": -1,
        "Privileged": false,
        "PortBindings": {
            "8001/tcp": [
                {
                    "HostIp": "",
                    "HostPort": "8001"
                }
            ]
        },
        "Links": null,
        "PublishAllPorts": false,
        "Dns": [],
        "DnsOptions": [],
        "DnsSearch": [],
        "ExtraHosts": null,
        "VolumesFrom": null,
        "Devices": [],
        "NetworkMode": "default",
        "IpcMode": "",
        "PidMode": "",
        "UTSMode": "",
        "CapAdd": null,
        "CapDrop": null,
        "GroupAdd": null,
        "RestartPolicy": {
            "Name": "no",
            "MaximumRetryCount": 0
        },
        "SecurityOpt": null,
        "ReadonlyRootfs": false,
        "Ulimits": null,
        "LogConfig": {
            "Type": "json-file",
            "Config": {}
        },
        "CgroupParent": "",
        "ConsoleSize": [
            0,
            0
        ],
        "VolumeDriver": ""
    },
    "GraphDriver": {
        "Name": "aufs",
        "Data": null
    },
    "Mounts": [
        {
            "Source": "/Users/dave/Sites/davesrepo/dynamo",
            "Destination": "/var/dynamo",
            "Mode": "",
            "RW": true
        }
    ],
    "Config": {
        "Hostname": "7d3d338891aa",
        "Domainname": "",
        "User": "",
        "AttachStdin": false,
        "AttachStdout": false,
        "AttachStderr": false,
        "ExposedPorts": {
            "8001/tcp": {}
        },
        "Tty": true,
        "OpenStdin": false,
        "StdinOnce": false,
        "Env": [
            "APP_ENV=development",
            "PYTHONPATH=$PYTHONPATH:/var/dynamo",
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "LANG=C.UTF-8",
            "PYTHON_VERSION=3.5.1",
            "PYTHON_PIP_VERSION=7.1.2"
        ],
        "Cmd": [
            "python3"
        ],
        "Image": "davesrepo/dynamo",
        "Volumes": null,
        "WorkingDir": "/var/dynamo",
        "Entrypoint": null,
        "OnBuild": null,
        "Labels": {},
        "StopSignal": "SIGTERM"
    },
    "NetworkSettings": {
        "Bridge": "",
        "SandboxID": "71d99a7d11908a9d1c0156fd33eb3f0ff5ef9f6697bb77103fe2caa1cf488530",
        "HairpinMode": false,
        "LinkLocalIPv6Address": "",
        "LinkLocalIPv6PrefixLen": 0,
        "Ports": {
            "8001/tcp": [
                {
                    "HostIp": "0.0.0.0",
                    "HostPort": "8001"
                }
            ]
        },
        "SandboxKey": "/var/run/docker/netns/71d99a7d1190",
        "SecondaryIPAddresses": null,
        "SecondaryIPv6Addresses": null,
        "EndpointID": "1cc99b0de89700368f31b43248c90ea45cec756712a2bd2ba2dc57293a5d0a72",
        "Gateway": "172.17.0.1",
        "GlobalIPv6Address": "",
        "GlobalIPv6PrefixLen": 0,
        "IPAddress": "172.17.0.2",
        "IPPrefixLen": 16,
        "IPv6Gateway": "",
        "MacAddress": "02:42:ac:11:00:02",
        "Networks": {
            "bridge": {
                "EndpointID": "1cc99b0de89700368f31b43248c90ea45cec756712a2bd2ba2dc57293a5d0a72",
                "Gateway": "172.17.0.1",
                "IPAddress": "172.17.0.2",
                "IPPrefixLen": 16,
                "IPv6Gateway": "",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "MacAddress": "02:42:ac:11:00:02"
            }
        }
    }
}
]

Docker version is 1.9.1

解决方案

Docker & Virtualbox seem to have an issue with mounting a volume outside of the /Users directory. The only way to fix the issue is to delete the docker machine image, properly set the /Users/yourname directory as the share folder in Virtualbox and create a new docker machine image.

Steps to fix the issue:

  1. docker-machine stop dev
  2. docker-machine rm dev
  3. docker-machine create --driver virtualbox dev
  4. eval "$(docker-machine env dev)"
  5. docker build -t davesrepo/dynamo -f ./Dockerfile .
  6. docker run -v $(pwd):/var/dynamo -d -t -p 8001:8001 --env-file ./dynamo.env --name dynamo davesrepo/dynamo
  7. docker exec -it dynamo /bin/bash
  8. ls

root@42f9e47fa2de:/var/dynamo# ls Dockerfile README.md __init__.py __pycache__ bin config.ini requirements.txt seed.sql tests

Files!

这篇关于Docker Volume 没有挂载任何文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆