当前位置:  开发笔记 > 编程语言 > 正文

Docker Volume没有安装任何文件

如何解决《DockerVolume没有安装任何文件》经验,为你挑选了2个好方法。

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

使用run命令:

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

用我的 Dockerfile

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

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

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 ..

运行docker inspect dynamo显示正确安装的目录

[
{
    "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版本是1.9.1



1> digitaldaven..:

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

解决问题的步骤:

    docker-machine stop dev

    docker-machine rm dev

    docker-machine create --driver virtualbox dev

    eval "$(docker-machine env dev)"

    docker build -t davesrepo/dynamo -f ./Dockerfile .

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

    docker exec -it dynamo /bin/bash

    ls

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

文件!



2> roy..:

我发现我更改了Windows密码,并且docker需要Windows凭据才能装载卷,您可以更新设置>共享驱动器。

推荐阅读
刘美娥94662
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有