Skip to content

Instantly share code, notes, and snippets.

@Jupiterrr
Last active August 29, 2015 14:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jupiterrr/5348f7f95df7de2888f0 to your computer and use it in GitHub Desktop.
Save Jupiterrr/5348f7f95df7de2888f0 to your computer and use it in GitHub Desktop.
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