相对路径不适用于docker-compose.yml中的命名卷 [英] Relative path not working with named volumes in the docker-compose.yml

查看:304
本文介绍了相对路径不适用于docker-compose.yml中的命名卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使命名卷使用执行 docker-compose 命令的文件夹的相对路径。

I need to make a named volume use a relative path to the folder where the docker-compose command is executed.

这是docker-compose.yml中的卷定义

Here is the volume definition in the docker-compose.yml

volumes:
  esdata1:
   driver: local 
   driver_opts:
      type: none
      device: ./esdata1
      o: bind

似乎 docker-compose做如果该文件夹不存在,则不创建该文件夹,但是即使在启动docker之前创建了该文件夹,我也总是收到此错误:

It seems that docker-compose do not create the folder if it does not exist, but even when the folder is created before lauching docker I'm always getting this error:

ERROR: for esdata  Cannot create container for service esdata: error while mounting volume with options: type='none' device='./esdata1' o='bind': no such file or directory

注意:这也许很愚蠢,但是 esdata 是使用命名的服务量

NOTE: This is maybe silly, but esdata is the service that use the named volume

  esdata:
    ...
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    ...

我在这里缺少什么?

也许相对路径。/并不指向 docker- compose 被执行(我尝试使用〜/ 使用相对于用户家的文件夹,但出现相同的错误)。

Maybe the relative path ./ does not point to the folder where the docker-compose is executed (I've tried with ~/ to use a folder relative the user's home but I got the same error).

预先感谢

PS:如果我使用绝对路径,它就像一个魅力

PS: If I use an absolute path it works like a charm

推荐答案

我遇到了完全相同的问题。看来您没有做错任何事。 Docker尚未实现: https://github.com/docker/compose/issues / 6343

I encountered exactly the same issue. It seems that you have done nothing wrong. This is just not yet implemented in Docker : https://github.com/docker/compose/issues/6343

可移植性不是很好...

Not very nice for portability...

这篇关于相对路径不适用于docker-compose.yml中的命名卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆