理解Dockerfile volume与docker-compose.yml volume
First we should know, Dockerfile is not docker-compose.yml.
Dockerfile
is the file run by docker build -t image:tag .
for making a docker image.
But the docker-compose.yml
is the file run by docker-compose up
for start a docker container or several containers.
They are both files that collecting many orders, which make the building process clearly and organized.
-
Volumes in docker
From Volumes and Dockerfiles Don’t Mix , Volumes with Docker are a popular topic.
-
Don’t Create Volumes Inside a Dockerfile
The practice which Specifying a Volume through creating an image, has no upside, and lots of problems that it creates:
-
Issue#1 Anonymous Volumes
Defining a volume inside the image tells docker to store this data separate from the rest of the container, even if you don’t define the volume when you spin up the container.
Docker’s way of storing this data is to create a local volume without a name.
The name itself is a long unique id string that contains no reference to the image or container it’s attached to.
And unless you explictly tell docker to remove volumes when you remove the container, these volumes remain ,unlikely to ever be used again:
# 查看dockerfile定义的volume docker volume ls # 删除dockerfile定义的volume
-
Issue#2 You Cannot Modify a Volume Once Created, Sometimes
-
Issue#3 Derived Images Cannot Modify the Volume Either
-
-
You can Use Volumes Without Defining Them Inside the Image
All of these issues begs the question:
“If I shouldn’t define volumes inside the
Dockerfile
, then how can I use volumes in docker?”"use the
docker-compose.yml
ordocker run
"From docker-compse.yml or docker run methods, you can not only define your volume, but you can give it a name.
-
-
docker-compose.yml
From Frequently asked questions on docker docs, The volume (docker-compose.yml) overrides the directory contents of the image.
-
References
上一篇: machine_learning
推荐阅读
-
浅谈docker Dockerfile 指令 VOLUME 介绍
-
浅谈docker Dockerfile 指令 VOLUME 介绍
-
Dockerfile 之 VOLUME
-
Dockerfile 指令 VOLUME 介绍
-
理解Dockerfile volume与docker-compose.yml volume
-
Dockerfile 指令 VOLUME 介绍
-
Dockerfile Volume指令与docker -v的区别
-
docker 高级 容器的挂载 与数据卷 -v volumes volume docker挂载 容器间数据共享 宿主机与容器数据共享 主机与docker共享数据
-
013-Dockerfile-VOLUME
-
Dockerfile 中的 VOLUME 与 docker -v 区别