Docker容器无法挂载文件夹

时间:2018-10-03 06:35:45

标签: docker volume mount

我正在处理一个应用程序。使用NodeJS语言和docker docker-compose进行部署。

我有一个用于上传文件的端点。当我上载文件应用程序时,将其保存在“文件”文件夹中(文件文件夹位于项目的根目录)。容器重新启动时,我不想丢失文件,因此我创建了一个名为“ myfiles”的卷并将其安装到“ / files”路径。

但是当我检查myfiles卷路径时,我没有看到任何由api创建的文件。如果我重新启动容器,上传的文件就会消失。

这是我的api的docker-compose.yaml文件

version: '3.1'

services:
  api:
    image: api-image
    restart: always
    volumes:
      - myfiles:/files
volumes:
  myfiles:

docker-compose up -d之后,我上传了一些文件,并通过调用在容器中查看了它们

docker exec -it container_name ls files node_modules package.json index.js package-lock.json src

docker exec -it container_name ls files d5a3455a39d8185153308332ca050ad8.png

文件创建成功。

我检查了容器是否正确安装 docker inspect container_name和结果:

"Mounts": [
        {
            "Type": "bind",
            "Source": "/var/lib/docker/volumes/myfiles/_data",
            "Destination": "/files",
            "Mode": "rw",
            "RW": true,
            "Propagation": "rslave"
        }
    ]

1 个答案:

答案 0 :(得分:1)

您正在创建卷,没有使用文件夹。尝试使用当前目录中的文件夹#include <SFML/Graphics.hpp> #include <vector> int main() { sf::RenderWindow window({640, 480}, "Hexagons"); // We're simply abusing a `CircleShape` here, // since a circle defined by 6 points IS a hexagon! sf::CircleShape hexagon(25, 6); hexagon.setOutlineColor(sf::Color::Black); hexagon.setOutlineThickness(5); hexagon.setFillColor(sf::Color::White); hexagon.setOrigin(25, 25); while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } window.clear(sf::Color::White); for (int y = 0; y < 10; ++y) { for (int x = 0; x < 10; ++x) { // The horizontal/vertical offsets of 50 and 40 // might feel off, but that's due to the way SFML // calculates the circle outline hexagon.setPosition((y % 2 ? 75 : 50) + x * 50.f, 50 + y * 40.f); hexagon.setFillColor(sf::Color(x * 25, y * 25, 0)); window.draw(hexagon); } } window.display(); } }

myfiles
相关问题