[英]docker failed to mount local volume mount no such file or directory
I'm trying to run my image like this:我正在尝试像这样运行我的图像:
version: '3.8'
services:
gamit:
image: myimage
volumes:
- app:/app
volumes:
app:
driver: local
driver_opts:
type: none
device: ./app
o: bind
At first my goal was to have an app
directory near my docker-compose.yml
file that (app directory) should persist an app
directory from inside a container (it already contains some important data).起初我的目标是在我的
docker-compose.yml
文件附近有一个app
目录,(应用程序目录)应该从容器内部保留一个app
目录(它已经包含一些重要数据)。 My deploy scenario assumes that this directory is initially empty on host and then keeps up with changes from inside container.我的部署场景假设这个目录最初在主机上是空的,然后跟上容器内部的变化。 When I was running it with
docker compose up
my app
directory near the docker-compose.yml
remained empty.当我使用 docker 运行它时,在
docker-compose.yml
附近docker compose up
我的app
目录仍然为空。 I noticed that /var/lib/docker/volumes/myimage/_data
was created and populated with data from container (I assumed from another stackoverflow questions that my device:./app
option sets the location of host directory).我注意到
/var/lib/docker/volumes/myimage/_data
已创建并填充了来自容器的数据(我从另一个 stackoverflow 问题中假设我的device:./app
选项设置了主机目录的位置)。 Then I've removed /var/lib/docker/volumes/myimage/
directory and now it throws me an error docker failed to mount local volume mount no such file or directory
.然后我删除了
/var/lib/docker/volumes/myimage/
目录,现在它给我一个错误docker failed to mount local volume mount no such file or directory
。 My general goal is to initially run docker compose up
with an empty app
directory, populate it from inside the container and then have all changes from inside the container in it.我的总体目标是最初运行
docker compose up
一个空的app
目录,从容器内部填充它,然后从容器内部进行所有更改。
In ubuntu 20.04, Docker version 20.10.17 and Docker compose version v2.6.0在 ubuntu 20.04、Docker 版本 20.10.17 和 Docker 组成版本 v2.6.0
I try to use: ${PWD}/app instead of ./app .我尝试使用: ${PWD}/app而不是./app 。 like this:
像这样:
version: '3.8'
services:
gamit:
image: myimage
volumes:
- app:/app
volumes:
app:
driver: local
driver_opts:
type: none
device: ${PWD}/app
o: bind
It works fine for me.这对我来说可以。 As I know for the local volume In Docker, you need to have an absolute path for mounting.
据我所知,对于本地卷在 Docker 中,您需要有一个安装的绝对路径。 ${PWD} environment variable shows the current path of your project.
${PWD}环境变量显示项目的当前路径。 But sometimes ${PWD} in some versions of Docker or some versions of Docker Compose do not work well
但有时${PWD}在某些版本的 Docker 或某些版本的 Docker 中 Compose 无法正常工作
There is suitable information at https://docs.docker.com/engine/install/linux-postinstall/ https://docs.docker.com/engine/install/linux-postinstall/上有合适的信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.