Quick and dirty real-time sync of local dir into a container (perhaps in Kubernetes)

OK this is a bit of a hack. But lets say you want to be editing files in a directory. Each time you write one, you want it synced into some container. This is obviously for development purposes. Well I present the below hacklet. It uses the inotifycall of Linux, watching the current directory. Each time a file is written, in my example, it calls docker cp. Feel free to make that kubectl cp or another action.

Warranty void where prohibited.

inotifywait -m $PWD -e modify | while read path action file
do 
  echo sync $file
  docker cp $file CONTAINER:PATH/
done

 


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *