官方Docker初学者教程上的Docker卷与持久卷 [英] Docker volume vs. persistent volume on official Docker beginner tutorial
问题描述
该教程位于 docker-curiculum
我在本教程的 docker-compose.yml
中无法理解卷之间的差异:
I am having trouble understanding the difference between volumes in this docker-compose.yml
in the tutorial:
version: "3"
services:
es:
image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
container_name: es
environment:
- discovery.type=single-node
ports:
- 9200:9200
volumes:
- esdata1:/usr/share/elasticsearch/data
web:
build: . # replaced image with build
command: python app.py
environment:
- DEBUG=True # set an env var for flask
depends_on:
- es
ports:
- "5000:5000"
volumes:
- ./flask-app:/opt/flask-app
volumes:
esdata1:
driver: local
在 web
, es
下有 volumes
,然后单独使用 esdata1:
和 driver:本地
在其下方.我的新手理解 web
和 es
下的内容是将外部数据装载到每个容器中的目录中.然后,最后一个 volume
将永久卷放在主机上,即使容器被杀死,该卷也将存在于该主机上.在这种情况下,将保留 esdata1:
数据.我的下一个问题是 driver:local
是什么意思?
There are volumes
under web
, es
and then by itself with esdata1:
and driver: local
underneath it. My newbie mind understands the ones under web
and es
to be mounts of external data to a directory within each container. Then the last volume
is putting a persistent volume on the host machine that will be there even when containers are killed. In this case, it is esdata1:
data that will persist. My next question is, what does the driver: local
mean?
推荐答案
我刚刚收到一位导师的建议,是的,我的猜测部分正确,因为Docker将在/var/lib/docker/下创建一个目录卷
,并且该目录可以挂载到容器中.该持久卷成为容器内进程数据的存放位置,即MySQL,ElasticSearch等被永久存储.(我猜直到你杀了,用 -v
选项删除所有内容……只是一个猜测). web
下的卷是程序员创建的目录,即.包含 app.py
的相同子目录,该子目录安装在容器中,允许即时重写 app.py
,即.在本地计算机上进行的任何更改都会反映在容器中.
作为容器和Docker的新手,尽管学习曲线对我而言有些陡峭,但这一切都非常有效.请参阅上面的评论,并带有指向另一个问题的链接,以回答第二个问题.
I just received advice from a mentor and yes, my guess is partially correct in that Docker will create a directory at /var/lib/docker/volumes
and that directory can be mounted to containers. This persistent volume becomes the location where data from processes inside containers, ie. MySQL, ElasticSearch, etc, is permanently stored.
(I'm guessing until you kill, delete everything with the -v
option...just a guess).
The volume under web
is the directory created by the programmer, ie. same subdirectory that contains app.py
that is mounted in the container allowing rewrite of app.py
on the fly, ie. whatever changes are made on the local machine are reflected in the container.
As a newbie to containers and Docker, this all seems very efficient although the learning curve is somewhat steep for me. Please see above comments with link to another question for answer to the second question.
这篇关于官方Docker初学者教程上的Docker卷与持久卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!