- ${container} is the name of the container
- ${src_dir} is the source dir
- ${dst_dir} is the destination dir
copying a dir out of a container
docker exec ${container} tar -cf - -C $(dirname ${src_dir}) $(basename ${src_dir})
| tar -xf - -C ${dst_dir}
copying a dir into a container
tar -cf - -C $(dirname ${src_dir}) $(basename ${src_dir})
| docker exec -i ${container} tar -xf - -C ${dst_dir}
setting files uid/gid
A tar-pipe can also set the destination files owner/uid and group/gid:tar --owner=UID --group=GID -cf - -C $(dirname ${src_dir}) $(basename ${src_dir})
| docker exec -i ${container} tar -xf - -C ${dst_dir}
This is useful because unlike [docker run] the [docker cp] command does not have a [--user] option.
Alpine tar update
The default tar on Alpine Linux does not support the --owner/--group options. You'll need to:apk --update add tar
Hope this proves useful!
Thank you.
ReplyDeletePleasure :-)
ReplyDelete