I’m playing a lot with Docker lately. Building images, and then rebuilding, and then building again… It’s pretty boring. To automate this task a little I used inotify to build automatically after I changed any file. This trick could be used in many different situations.

On Linux

You will need inotify-tools package:

sudo apt-get install -y inotify-tools

Then run something like this:

while inotifywait -e modify -r .; do docker-compose build; done

On MacOS

You will need fswatch tool:

brew install fswatch

Then:

fswatch -o . | xargs -n1 -I{} docker-compose build

Both commands will rebuild my Docker images after any file change in current directory. Use Ctrl+c to exit from loop.