如何使用Docker Compose在Docker容器中将主机目录作为卷挂载

时间:2020-07-01 10:03:50

标签: docker docker-compose

我有一个目录models,其中包含4个文件。我试图将其作为卷安装在我的容器中,如下所示:

volumes:
    - /home/andrew/Documents/models/:/home/andrew/Documents/models/

但是它总是让我抛出这个错误:

"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 ERROR: Encountered errors while bringing up the project.

我正在使用docker-compose的2.4版本。谁能告诉我这是什么问题。谢谢

1 个答案:

答案 0 :(得分:0)

如果必须更新语法。简短语法为:[SOURCE:]TARGET[:MODE]格式。 TARGET是安装卷的容器路径。

  # Path on the host, relative to the Compose file
  - ./cache:/tmp/cache

  # User-relative path ~ == /home/username And  container path where the volume is mounted
  - ~/configs:/var/lib/:ro

Compose volumes - version 2 reference]