【问题标题】:How to access a file outside from a docker container?如何从 docker 容器访问外部文件?
【发布时间】:2021-07-16 10:45:10
【问题描述】:

我使用 django 作为我的框架。 为了管理我们使用 docker 的服务器。

当我尝试运行时:

docker-compose exec -T  web python3 manage.py shell < /data01/ipse/litework/second_level_controller/load.py

加载一些数据我得到以下错误:

文件“/code/second_level_controller/DataBaseLoader.py”,第 53 行,在 load_filenames 中 with open(os.path.join(self.data_directory, 'manifest.txt')) as f:

FileNotFoundError: [Errno 2] 没有这样的文件或目录: '/data01/ipse/rawdata/manifest.txt'

但文件 /data01/ipse/rawdata/manifest.text 存在,我可以正常访问该文件:

nano /data01/ipse/rawdata/manifest.txt 

如何正确访问文件?

【问题讨论】:

  • 看起来该文件是 Django 管理应用程序的一种脚本;它是否使用绝对路径引用脚本中的其他文件?你最初是如何启动容器的?

标签: django docker docker-compose file-not-found


【解决方案1】:

尝试为 /data01 添加卷挂载,以便这些文件位于 docker 映像内的相同位置。

https://docs.docker.com/storage/volumes/

https://docs.docker.com/compose/compose-file/compose-file-v3/#volume-configuration-reference

这看起来像:

services:
  webserver:
    image: python
    volumes:
       - /data01:/data01

【讨论】:

  • 不完全是我的答案,但它引导我朝着正确的方向前进。谢谢!
猜你喜欢
  • 2021-01-06
  • 1970-01-01
  • 2019-09-03
  • 2020-11-15
  • 1970-01-01
  • 2016-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多