Create a gist now

Instantly share code, notes, and snippets.

@Jupiterrr /sync.sh
Last active Aug 29, 2015

What would you like to do?
This script syncs the current directory to /home/docker/share on a boot2docker vm.
#!/bin/bash
set -u # prevent unbound variables
set -e # terminate on error
SSH_PORT=$(boot2docker config 2>&1 | awk '/SSHPort/ {print $3}')
# install rsync
boot2docker ssh tce-load -wi rsync
# ensure existance of .rsyncignore
touch .rsyncignore
function boot2docker_sync {
# sync current directory to ~/share on the vm
rsync \
-rlz --force --delete \
--exclude-from=.rsyncignore \
-e "ssh \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
-i $HOME/.ssh/id_boot2docker \
-p $SSH_PORT" \
./ docker@localhost:/home/docker/share
echo "sync: $(date)"
}
export -f boot2docker_sync
boot2docker_sync
fswatch -o . | xargs -n1 -I{} boot2docker_sync
$ curl -o sync.sh https://gist.githubusercontent.com/Jupiterrr/5348f7f95df7de2888f0/raw/686aa3f7b1de0b5e13bfefaf63b42c398b9b021b/sync.sh
$ sh sync.sh

To mount your current directroy into a container you need to reference /home/docker/share:

$ docker run -v /home/docker/share:/share busybox ls /share

Use the .rsyncignore file to ignore files or directories you don't want to sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment