How to copy multiple files into a docker data volume

守給你的承諾、 提交于 2020-01-24 05:09:11

问题


It may sound trivial but I couldn't find a easy way to copy multiple files into the root folder of a docker volume. I am using Ubuntu Xenial 16.04 and Docker 1.12.1. For example if I have an Ubuntu container with the volume /my_data:

docker run --name my_container -v /my_data -d ubuntu:latest 

In my host machine I have a folder called /tmp/my_data/ with multiple files inside, and I would like to copy all those files into the volume /my_data in my_container. I have tried the following approaches but none of them work:

docker cp /tmp/my_data my_container:/
docker cp /tmp/my_data/* my_container:/my_data/

Does someone know a work around for this issue?


回答1:


Actually it was easier than I though, just need to add a dot in the host path and it will work as expected, copying all files and folders within /my_data folder

docker cp /tmp/my_data/. my_container:/my_data



回答2:


As a workaround you can create a loop:

for i in /tmp/my_data/*;do docker cp /tmp/my_data/"$i" my_container:/my_data/;done

*Note: The specific workaround wont copy hidden files or folders inside the my_data folder.



来源:https://stackoverflow.com/questions/39419702/how-to-copy-multiple-files-into-a-docker-data-volume

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