如何将计算机中的文件添加到Docker容器中?

时间:2016-12-31 20:19:42

标签: docker

目标:

我正在尝试将文件从我的计算机复制到以下存储库中:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
crisbal/torch-rnn   base                90e6f8c8be88        7 months ago        1.173 GB

信息:

我检查了IMAGE ID,以便找到Container值。

$ docker inspect 90e6f8c8be88 输出

[
    {
        "Id": "sha256:90e6f8c8be88e51e1bbca2bd6e5288d49ef07cd7bb39fea92b1e5ff22359635f",
        "RepoTags": [
            "crisbal/torch-rnn:base"
        ],
        "RepoDigests": [
            "crisbal/torch-rnn@sha256:b379131dc0356a2d0be3b16c8aadccafea8d18a2a81dda5af53136c9ac0cf9
7e"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2016-05-15T12:11:40.123276779Z",
        "Container": "dbd5803b8c916411205323a11c005e15347b4b9496f1e32f571dbe65c43b8719",
        "ContainerConfig": {
            "Hostname": "3713552cb044",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/root/torch/install/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbi
n:/bin",
                "DEBIAN_FRONTEND=noninteractive",
                "DEBCONF_NONINTERACTIVE_SEEN=true",
                "LUA_PATH=/root/.luarocks/share/lua/5.1/?.lua;/root/.luarocks/share/lua/5.1/?/init.l
ua;/root/torch/install/share/lua/5.1/?.lua;/root/torch/install/share/lua/5.1/?/init.lua;./?.lua;/roo
t/torch/install/share/luajit-2.1.0-beta1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5
.1/?/init.lua",
                "LUA_CPATH=/root/torch/install/lib/?.so;/root/.luarocks/lib/lua/5.1/?.so;/root/torch
/install/lib/lua/5.1/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so",
                "LD_LIBRARY_PATH=/root/torch/install/lib:",
                "DYLD_LIBRARY_PATH=/root/torch/install/lib:"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) WORKDIR /root/torch-rnn"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:4742fe1066703d83130ca9a669b44a431702ffc8b776601aebe126e7db50c906",
            "Volumes": null,
            "WorkingDir": "/root/torch-rnn",
            "Entrypoint": null,
            "OnBuild": [],
            "Labels": {}
        },
        "DockerVersion": "1.10.2",
        "Author": "Cristian Baldi \"bld.cris.96@gmail.com\"",
        "Config": {
            "Hostname": "3713552cb044",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/root/torch/install/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbi
n:/bin",
                "DEBIAN_FRONTEND=noninteractive",
                "DEBCONF_NONINTERACTIVE_SEEN=true",
                "LUA_PATH=/root/.luarocks/share/lua/5.1/?.lua;/root/.luarocks/share/lua/5.1/?/init.l
ua;/root/torch/install/share/lua/5.1/?.lua;/root/torch/install/share/lua/5.1/?/init.lua;./?.lua;/roo
t/torch/install/share/luajit-2.1.0-beta1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5
.1/?/init.lua",
                "LUA_CPATH=/root/torch/install/lib/?.so;/root/.luarocks/lib/lua/5.1/?.so;/root/torch
/install/lib/lua/5.1/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so",
                "LD_LIBRARY_PATH=/root/torch/install/lib:",
                "DYLD_LIBRARY_PATH=/root/torch/install/lib:"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:4742fe1066703d83130ca9a669b44a431702ffc8b776601aebe126e7db50c906",
            "Volumes": null,
            "WorkingDir": "/root/torch-rnn",
            "Entrypoint": null,
            "OnBuild": [],
            "Labels": {}
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 1172734794,
        "VirtualSize": 1172734794,
        "GraphDriver": {
            "Name": "aufs",
            "Data": null
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:7394707b3914f5b790ab676160cf44bc8987afaf6cff498644e65dd464e5a7bf",
                "sha256:1822b2b471224231a3897509de16ee85cfa62e2141fd56adf3d90b83d11af4fd",
                "sha256:4e2fee1e7083e29fd2b6186410a40f334acfdcf0ad49343cfb19c728a971fd6d",
                "sha256:5b5be35aaec46eb9b8099c062436783f071b8d87bf039c4fc0b0748939ca71c8",
                "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef",
                "sha256:92d83bbbef9e6179f1d00c97a350c852472320340e89c84783f57839c7e674c9",
                "sha256:7efcc7a852afab84b20600433282efc6e5533cc8cc9fbfe169d6abfc98f3ad21",
                "sha256:579a21b228a5ed1f0ccd6f5627bbf377bf1b76826c6fb851ee1b247af7f30a82",
                "sha256:c1c66cc65895c9690f23cb4d14900a01af34b7ebff03950024211903ba500cbd",
                "sha256:d2a8da673882bb1a3a09d84ef5e5d322093413e469ecb10006b3c03839038361",
                "sha256:18d247d325a043c55b45df34e6585db08369662587eb327b2c3d34f5cc180c18",
                "sha256:df6148262d5b23a1d25487eff9edde40c36c18c7391802277456f69a8266693a",
                "sha256:afa2abf30b9efaab98ed72656f71799fcce353996ccd5be24c18be0016888690",
                "sha256:d75eea40967819b212498fc7e9d78dfc3e5483b04b0cd8b01d7c683b6c12a50e",
                "sha256:139fe6eee4b6d4bf9bd4cf1f4bf08caa3bafb70662e1ac1c670c7636309e1a07"
            ]
        }
    }
]

使用从检查中获取的容器值:

docker cp comments.txt dbd5803b8c916411205323a11c005e15347b4b9496f1e32f571dbe65c43b8719:/comments.txt

输出:

  

来自守护程序的错误响应:没有这样的容器:   dbd5803b8c916411205323a11c005e15347b4b9496f1e32f571dbe65c43b8719

如何将计算机中的文件添加到Docker容器中?

1 个答案:

答案 0 :(得分:2)

您看到和检查的内容是图片:crisbal/torch-rnn

您需要运行该图像的容器表单才能使用docker cp

  

docker cp实用程序会将SRC_PATH的内容复制到DEST_PATH   您可以从容器的文件系统复制到本地计算机,反之亦然,从本地文件系统复制到容器

您不会复制到该存储库中的存储库或图像中,而是复制到从该图像创建的正在运行(或已停止)的容器中。