简体   繁体   English

docker-compose将文件复制为文件夹

[英]docker-compose copies files as folder

I am trying to copy elasticsearch.yml with CORS enabled from my host to a container using docker-compose volumes option. 我正在尝试使用从主机启用的CORS将elasticsearch.yml复制到使用docker-compose卷选项的容器。 But when I copy the config folder it copies the elasticsearch.yml file in it as a folder. 但是当我复制config文件夹时,它会将elasticsearch.yml文件作为文件夹复制到其中。

Here is my docker-compose file: 这是我的docker-compose文件:

version: "3"

services:  
elasticsearch1:  
    container_name: my_container_name
    image: elasticsearch
    environment:
      - "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
    volumes:
      - /config/:/usr/share/elasticsearch/config/
    ports:
      - '9200:9200'
      - '9300:9300'

And this is the error message i get whe running docker-compose up: 这是运行docker-compose时出现的错误信息:

Exception in thread "main" SettingsException[Failed to load settings from /usr/share/elasticsearch/config/elasticsearch.yml]; 线程“main”中的异常SettingsException [无法从/usr/share/elasticsearch/config/elasticsearch.yml加载设置]; nested: IOException[Is a directory]; 嵌套:IOException [是一个目录];

I also tried copying to tmp folder, and file was listed as a folder: 我也尝试复制到tmp文件夹,文件被列为文件夹:

drwxr-xr-x 2 root root 40 Jul 6 08:25 elasticsearch.yml drwxr-xr-x 2 root root 40 Jul 6 08:25 elasticsearch.yml

What am I doing wrong? 我究竟做错了什么?

With Docker for Windows and Docker for Mac, you are running docker inside of a VM and mounting directories from inside that VM into your container. 使用适用于Windows的Docker和适用于Mac的Docker,您可以在VM内部运行docker,并将该VM中的目录安装到容器中。 When the file or directory doesn't exist inside the VM, it will get mounted as an empty folder by Docker as a default behavior (this behavior appears to be changing with swarm mode). 当VM内部不存在文件或目录时,它将作为默认行为被Docker挂载为空文件夹(此行为似乎随着swarm模式而改变)。

To get a folder from the windows host into the VM where it can then be mapped into a container, you need to go into the docker settings and configure your shared drives: 要将Windows主机中的文件夹放入VM,然后将其映射到容器,您需要进入docker设置并配置共享驱动器:

https://docs.docker.com/docker-for-windows/#shared-drives https://docs.docker.com/docker-for-windows/#shared-drives

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

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