带有数据库的 Dockerfile 卷 - 将卷用于可变的用户可维护部分

Dockerfile volume with database - using volume for mutable user-servicable parts

本文摘自docker官网Dockerfile best practices..

VOLUME

The VOLUME instruction should be used to expose any database storage area, configuration storage, or files/folders created by your docker container. You are strongly encouraged to use VOLUME for any mutable and/or user-serviceable parts of your image.

对图像的任何可变和用户可维护部分使用卷是什么意思?是否有时我 should/shouldnt 将卷用于数据库?如果是,为什么?这是您将数据库的实际数据内容与 docker 容器分开安装的地方..

不是一个完整的答案,但我找到了一个可能有帮助的例子。摘自 Oskar Hane 的书 "Build your own PAAS with Docker",他在其中创建了一个仅用于为其他容器托管文件的容器,例如 MySQL 容器:

Dockerfile 有一个VOLUME 指令,您可以使用--volumes-from 属性定义添加此数据卷容器时将哪些目录暴露给其他容器。在我们的数据卷容器中,我们首先需要为 MySQL 数据添加一个目录。让我们看看我们将使用的 MySQL 镜像内部,看看哪个目录用于数据存储,并将该目录暴露给我们的数据卷容器,以便我们可以拥有它:

RUN mkdir –p /var/lib/mysql 
VOLUME ["/var/lib/mysql"]