[Django]-How to copy files from host to docker named volume

7👍

You can make it this way:

docker run -d --rm --name temp -v django-media:/root alpine tail -f /dev/null
docker cp ./run/media/. temp:/root 
docker stop temp
docker exec -it --user root web /bin/bash
chown -R root:root /run/media

Creates a temp container with named volume mounted

docker run -d --rm --name temp -v django-media:/root alpine tail -f /dev/null

Then copy all files to temp container volume (./run/media/. copy all the files/folders inside to target dir /root)

docker cp ./run/media/. temp:/root 

then stops the temp container

docker stop temp

Now files are copied but without right permissions, exec a terminal inside the container that mounts the named volume, move to directory and run chown to own the copied files, in this case I asume that files inside container belongs to root:root and the files copied belongs to different user, you can check that with ls -la command.

docker exec -it --user root web /bin/bash
chown -R root:root /run/media

Leave a comment