Docker run --volume继续创建随机卷并且不使用指定的卷 [英] Docker run --volume keeps creating random volumes and not using the one specified

查看:88
本文介绍了Docker run --volume继续创建随机卷并且不使用指定的卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Docker会继续创建随机卷,而不是在运行 docker run ... 时使用我指定的卷.

Docker keeps creating random volumes instead of using the I specify when running docker run....

我将从没有卷开始.

$ docker volume ls
DRIVER              VOLUME NAME

我将创建一个

docker volume create myvol

它将被创建

$ docker volume ls
DRIVER              VOLUME NAME
local               myvol

我将使用该卷启动一个容器

I'll start a container using the volume

$ docker run -d \
  --name myapp \
  --publish 1337:1337 \
  --volume myvol:/my-work-dir/.tmp \
  foo/bar:tag

我将再次检查我的卷,我有创建的卷和新的卷.

I'll go and check my volumes again and I have the one I created and a new one.

$ docker volume ls
DRIVER              VOLUME NAME
local               9f7ffe30c24821c8c2cf71b4228a1ec7bc3ad6320c05451e42661a4e3c2c0fb7
local               myvol

为什么不使用 myvol ?为什么要创建新卷?

Why isn't myvol being use? Why is a new volume being created?

推荐答案

当您使用的映像将Dockerfile中的VOLUME定义为您在run命令中未定义为卷的容器路径时,会发生这种情况.当您有一个没有源(又名匿名卷)的卷时,Docker会为卷名称创建guid.您可以在图像上使用 docker image inspect 来查看该图像中定义的卷.如果检查容器( docker container inspect ),您会看到正在使用您的卷,只是第二个匿名卷也正在使用不同的路径.

This happens when the image you are using defines a VOLUME in the Dockerfile to a container path that you do not define as a volume in your run command. Docker creates the guid for the volume name when you have a volume without a source, aka an anonymous volume. You can use docker image inspect on the image to see the volumes defined in that image. If you inspect the container (docker container inspect), you'll see that your volume is being used, it's just that there's a second anonymous volume to a different path also being used.

这篇关于Docker run --volume继续创建随机卷并且不使用指定的卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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