Docker卷持久 [英] Docker volume persistent

查看:63
本文介绍了Docker卷持久的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个关于Docker卷的问题.

I have two questions about docker volume.

首先:当我使用由 docker volume create 或docker-compose创建的卷运行docker时,默认目录上的新文件不会追加到该卷上.我举个例子:

First : When I run my docker with a volume which it creates with docker volume create or with docker-compose, new files on the default directory are not appended to the volume. I give an example :

docker volume create testdock-logs

docker run -d -p 80:80 --name testdock --restart=on-failure -v testdock-logs:/var/www/logs testdock:latest -s

此后,当我在/var/www/logs 上创建新文件或目录并构建映像testdocker时,在卷上找不到新文件.

After that when I create a new file or directory on /var/www/logs and build my image testdocker, I don't find my new file on the volume.

我在做什么错了?

推荐答案

Docker不会将卷中的文件替换为修改后的映像中的文件.这样做会破坏卷的用途,这是您必须存储的一个永久位置,该位置在创建容器时不会恢复为映像状态.

Docker doesn't replace files in a volume with those in a modified image. Doing so would defeat the purpose of a volume, this is the one persistent location you have to store data that isn't reverted back to the image state when the container is recreated.

如果您需要映像中的文件而不是卷中的文件,请重新考虑是否确实需要卷.

If you need the files from your image instead of the files in your volume, then reconsider whether you actually need a volume.

这篇关于Docker卷持久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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