Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy multiple files into a docker data volume

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?

like image 782
Ander Avatar asked Sep 09 '16 21:09

Ander


1 Answers

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
like image 197
Ander Avatar answered Sep 30 '22 22:09

Ander