Reputation: 4404
I have a spring-boot application running on java images in container. In Dockerfile I am copying jar file. Then build custom image for my project & run it
I am thinking what if I will volume-map my jar file. At least it will run for the first time. I want some functionality like when I change volume map file in my host computer the docker need to be rerun.
For HTML, nginx will work fine as it is just rendering html files in the particular folder without rerun. But, I doubt if it will work for java
For rerun automatically what is the commands. Will it happens automatically?
Upvotes: 2
Views: 722
Reputation:
What you need to do is supervise your file using inotify, and whenever this file changes, call the Docker API so that it resets the container.
In order to call the Docker API from inside a container, you mount the Docker socket inside the container like this:
docker container run -it -v /var/run/docker.sock:/var/run/docker.sock ubuntu
You then install the required utilities inside the container:
apt-get update; apt-get install -y curl inotify-tools
You then write the script that should be called whenever your target file changes:
echo "curl --unix-socket /var/run/docker.sock -X POST http:/v1.24/containers/<container_to_reset>/restart" > script
chmod +x ./script # Make sure the script is executable
Finally, you run a loop that executes your script whenever the target file is modified:
while inotifywait -e close_write <target_file>; do ./script; done
Upvotes: 1