I want to use rsync within order to synchronize a folder. docker-machine allows rsync with the -d option.
docker-machine scp -r -d . machine-name:~
This command seems to be working, however, I would like to extend the use of rsync to:
rsync -rvz --delete --exclude-from=.rsyncignore -e 'docker-machine ssh machine-name' . :
I also tried the following command:
sshpass -p "tcuser" rsync -rvz --delete --exclude-from=.rsyncignore . docker@`docker-machine ip machine-name`:
Both command synchronize everything a first time, however, once everything is synced, I cannot access the VM anymore. If I try to access the VM through docker-machine ssh machine-name i receive the responseexit status 255. What is happening?
You can find more about here
1.-The Dockerfile
FROM centos:6
# install rsync
RUN yum update -y
RUN yum -y install rsync xinetd
# configure rsync
ADD ./rsyncd.conf /root/
RUN sed -i 's/disable[[:space:]]*=[[:space:]]*yes/disable = no/g' /etc/xinetd.d/rsync # enable rsync
RUN cp /root/rsyncd.conf /etc/rsyncd.conf
RUN /etc/rc.d/init.d/xinetd start
RUN chkconfig xinetd on
# create the dir that will be synced
RUN mkdir /home/share
# just to keep the container running
CMD /etc/rc.d/init.d/xinetd start && tail -f /dev/null
2.-Build the container within the repository directory.
docker build . -t docker-rsync
3.-For start the container and map the rsync server port to a specific host port, like to
docker run -p 10873:873 docker-rsync
4.-Now we need to sync our share directory and sync any changes again as soon as anything changes. Rsync will only sync changes after an initial sync.
# initial sync
rsync -avP ./share --delete rsync://localhost:10873/example/
# sync on change
fswatch -0 ./share | xargs -0 -n 1 -I {} rsync -avP ./share --delete rsync://localhost:10873/example/
UPGRADE: because docker machines change content and virtual disk need upgrade
first command when changed files in docker containers :
rsync --ignore-existing --sparse ...
second when docker machine create new files in containers sparse mode ,followed by:
rsync --inplace ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With