In docker, can I publish a volumes with initial data?

半城伤御伤魂 提交于 2019-12-24 00:49:20

问题


I want to share a file storage between two containers. From the documentation, I've seen that you can create and use volumes like this:

docker volume create --name DataVolume1
docker run -ti --rm -v DataVolume1:/datavolume1 ubuntu

However, I want containers to be able to access an initial set of shared data. Does docker support publishing of volumes? If not, does this mean I should write the initial data manually, after creating the volume, or is there another solution for publishing the data along with the images?


回答1:


With a named volume (not with a host volume, aka bind mount) docker will initialize an empty named volume to the contents of the image at the location you mount it. So if you have files in your image at /datavolume1, and DataVolume1 is empty, docker will copy those files into the named volume.



来源:https://stackoverflow.com/questions/46648697/in-docker-can-i-publish-a-volumes-with-initial-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!