简体   繁体   English

Docker 卷将文件绑定为远程 linux 服务器上的目录

[英]Docker volume binds file as directory on remote linux server

I have docker installed on linux on remote server.我在远程服务器上的 linux 上安装了 docker。 I use ssh to connect to docker from my host machine with Windows 10. To deploy my app to docker, I use docker-compose v3, but I have serious problem.我使用 ssh 从装有 Windows 10 的主机连接到 docker。要将我的应用程序部署到 docker,我使用 docker-compose v3,但我遇到了严重的问题。 When I try to mount volume with file from my host machine, file converts to directory in my container.当我尝试使用主机上的文件挂载卷时,文件将转换为容器中的目录。
Here's my docker-compose.yml:这是我的 docker-compose.yml:

version: "3.8"
services:
zeebe:
    container_name: zeebe
    image: camunda/zeebe
    environment:
      - ZEEBE_LOG_LEVEL=debug
    ports:
      - "26500:26500"
      - "9600:9600"
      - "5701:5701"
    volumes:
      - zeebe_data:/usr/local/zeebe/data
      - type: bind
        source: ./ZeebeServer/lib/application.yml
        target: /usr/local/zeebe/config/application.yaml
        read_only: true
    depends_on:
      - elasticsearch
    networks:
      - backend
  operate:
    container_name: operate
    image: camunda/operate
    ports:
      - "8080:8080"
    depends_on:
      - zeebe
      - elasticsearch
    volumes:
      - operate_data:/usr/local/operate
      - type: bind
        source: C:/Users/Aset/IdeaProjects/ABC-Store/ZeebeServer/operate/application.yml
        target: /usr/local/operate/config/application.yml
        read_only: true
    networks:
      - backend
  elasticsearch:
    container_name: elasticsearch
    image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.7.1
    ports:
      - "9200:9200"
    environment:
      - discovery.type=single-node
      - cluster.name=elasticsearch
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    volumes:
      - zeebe_elasticsearch_data:/usr/share/elasticsearch/data
    networks:
      - backend

And this is my error after command docker-compose -d up:这是命令 docker-compose -d up 后我的错误:

ERROR: for zeebe  Cannot start service zeebe: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/c/Users/User/IdeaProjects/ABC-Store/ZeebeServer/lib/application.yml\\\" to rootfs \\\"/var/lib/docker/overlay2/fec3c1f3ad8748e2bf3aa5fdf30558434c2474ecac8b7fdbad2fdbb27df24415/merged\\\" at \\\"/var/lib/docker/overlay2/fec3c1f3ad8748e2bf3aa5fdf30558434c2474ecac8b7fdbad2fdbb27df24415/merged/usr/local/zeebe/config/application.yaml\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

I understand that you are trying to mount a local folder from your Windows host ( C:/Users/Aset/IdeaProjects/... ) into a docker container.我了解到您正在尝试将本地文件夹从 Windows 主机 ( C:/Users/Aset/IdeaProjects/... ) C:/Users/Aset/IdeaProjects/...C:/Users/Aset/IdeaProjects/...容器中。

But this is not possible (that easily) since docker can only mount folders local to the docker host ie your remote server you're connecting to via ssh.但这不可能(那么容易),因为docker只能挂载本地文件夹到docker 主机,即您通过 ssh 连接到的远程服务器。

So in order to mount the folder of your local Windows host into the container you'd first have to mount that folder somehow on the docker host/remote server (eg with a Samba share) or copy the contents of that folder to the remote server and edit your volume source to the path of the folder on the docker host .因此,为了将本地 Windows 主机的文件夹安装到容器中,您首先必须以某种方式在 docker 主机/远程服务器上安装该文件夹(例如使用 Samba 共享)或将该文件夹的内容复制到远程服务器并将您的卷源编辑为docker 主机上文件夹的路径。

PS in case you're wondering why this doesn't work but docker build with files from your Windows host does : docker build uploads the build context ie the current directory, to the docker host making its content available on the server. PS如果你想知道为什么,这并不工作,但docker build从Windows主机与文件的作用docker build上传即当前目录下生成背景下,泊坞窗主机使其内容在服务器上可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM