Skip to content

Instantly share code, notes, and snippets.

@istepanov
Last active October 18, 2016 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save istepanov/f1585f10bd77c34263cfc54ffa77de29 to your computer and use it in GitHub Desktop.
Save istepanov/f1585f10bd77c34263cfc54ffa77de29 to your computer and use it in GitHub Desktop.
Copy host folder to a Docker volume (preserving all file permissions and ownership)
#!/bin/bash
# this is the source folder. We want to copy its content to a Docker volume.
SRC_PATH='/opt/docker/gitlab/data'
# this is target volume name. Assuming it's not been created yet.
VOLUME_NAME='gitlab-data'
tar Ccf $(dirname $SRC_PATH) - $(basename $SRC_PATH) | docker run -i --rm -v $VOLUME_NAME:/data debian tar Cxpf /data - --strip-components=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment