为什么docker没有将文件复制到挂载目录?

时间:2017-01-10 08:16:50

标签: node.js docker dockerfile

我在Docker中安装时遇到问题。我只想保存并将图片返回到前端。

这是一个dockerfile:

FROM node:boron

WORKDIR /app
COPY . .
RUN npm install --production

RUN mkdir -p /app/public
VOLUME ["/app/public"]

CMD yum install imagemagick
# if we don't use this specific form, SIGINT/SIGTERM doesn't get forwarded
CMD node server.js

我正在使用skyliner.io进行部署。 检查我的形象我得到了:

[
    {
        "Id": "sha256:598085445f82a8324f41842a7ac4f93a55b009d93bfaf07e7ce7b8a4bc5918d9",
        "RepoTags": [
            "thurst-back-end:latest"
        ],
        "RepoDigests": [],
        "Parent": "",
        "Comment": "",
        "Created": "2017-01-09T16:05:50.958866532Z",
        "Container": "85457fb45353305715ea72297187fd6b88a019aa369426428c536a6a80450206",
        "ContainerConfig": {
            "Hostname": "45f28166fed1",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NPM_CONFIG_LOGLEVEL=info",
                "NODE_VERSION=6.9.4"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) CMD [\"/bin/sh\" \"-c\" \"node server.js\"]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:64249ddf0e9111ef191b1fb02d1af3ae2c7735f0509169a8e5fa6bc980a463ba",
            "Volumes": {
                "/app/public": {}
            },
            "WorkingDir": "/app",
            "Entrypoint": null,
            "OnBuild": [],
            "Labels": {}
        },
        "DockerVersion": "1.11.2",
        "Author": "",
        "Config": {
            "Hostname": "45f28166fed1",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NPM_CONFIG_LOGLEVEL=info",
                "NODE_VERSION=6.9.4"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "node server.js"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:64249ddf0e9111ef191b1fb02d1af3ae2c7735f0509169a8e5fa6bc980a463ba",
            "Volumes": {
                "/app/public": {}
            },
            "WorkingDir": "/app",
            "Entrypoint": null,
            "OnBuild": [],
            "Labels": {}
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 700375224,
        "VirtualSize": 700375224,
        "GraphDriver": {
            "Name": "overlay",
            "Data": {
                "RootDir": "/var/lib/docker/overlay/739c2f7ee799c2ec0e75beb02c24c084aa9545fa6f1680b6a65062bf5d6133e8/root"
            }
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:b6ca02dfe5e62c58dacb1dec16eb42ed35761c15562485f9da9364bb7c90b9b3",
                "sha256:60a0858edcd5aad240966e33389850e4328de4cfb5282977eddda56bffc7f95f",
                "sha256:53c779688d06353f7ba4fd7ce1d43ce146ad0278ebead0feea1846383c730024",
                "sha256:0a5e2b2ddeaa749d95730bad9be3e3a472ff6f80544da0082a99ba569df34ff3",
                "sha256:fa18e5ffd316beb0c4c929ea1fff8d559a73a366f30f1004bb06af3e9f800696",
                "sha256:604c78617f347c58e4ce0021f47928b7df3d799ea7c5e9367fa5a800e473dc06",
                "sha256:6a73c39a0ab65b5e2da69b9013fc7f50c8bf5be27c0cf5fb3b642a247a8993ca",
                "sha256:b7ce32b271bee3f3c614232448a4308cdfc4a2bf6f8db1436f51cb74ae5c15dc",
                "sha256:a276062d9f56b85bf34797301d74b761970c3e6ce0ccd3525f4535e675a0974e",
                "sha256:2f616e13f894a3a5c4dc33cbbcce345c51a704d56a70396cacdfb2e96e2ff9df",
                "sha256:c6dfd7a877dba2837cc46e906cde9aa6e1cc5f89c9c65cefa81f130d59e2c7ac"
            ]
        }
    }
]

了解问题的下一个命令:

$ docker volume ls
DRIVER              VOLUME NAME
local     2fe327f9a9d82d7ddad72e8d9dcda76e3212653e100c24453de9edbbf60fbe53

$ docker volume inspect 2fe327f9a9d82d7ddad72e8d9dcda76e3212653e100c24453de9edbbf60fbe53

[
    {
        "Name": "2fe327f9a9d82d7ddad72e8d9dcda76e3212653e100c24453de9edbbf60fbe53",
        "Driver": "local",
        "Mountpoint": "/var/lib/docker/volumes/2fe327f9a9d82d7ddad72e8d9dcda76e3212653e100c24453de9edbbf60fbe53/_data",
        "Labels": null
    }
]

当我不在容器中运行项目时 - 一切正常,文件保存到/public/images/:id/:id-user.jpg

但是当我在docker中运行项目时,文件位于/var/lib/docker/overlay/0a2bdfae85072dce01e470eb71f1199ab23d90eb6f9e573d6a65e06d3d387cce/upper/app/public/images

1 个答案:

答案 0 :(得分:1)

不确定我理解它是否正确,但可能是因为您的应用程序写入路径/公共?

你说当你不在容器中运行时,你得到/public/images/...,但是你的音量是/app/public,这是另一条路径,因此你写入容器容量..