ewolff / microservice

Sample of a Microservice setup for my book. Based on Spring Cloud / Netflix / Java / Docker / Docker Compose / Docker Machine / Vagrant
Apache License 2.0
725 stars 352 forks source link

Vagrantfile run directives only executed during provisioning #3

Closed Larzenegger closed 9 years ago

Larzenegger commented 9 years ago

The vagrant provisioning documentation states:

run - Run a container and configure it to start on boot.

I therefore assumed that during the first execution, the respective loop in the Vagrantfile would first build the docker images, then run the containers while also configuring them to start on subsequent calls. However, when I run

vagrant up

then check that the services were started (they were). Then run

vagrant halt vagrant up

the docker containers are not started. Message:

==> default: Machine already provisioned. Run vagrant provision or use the --provision ==> default: to force provisioning. Provisioners marked to run always will still run.

Perhaps I'm misunderstanding the procedure. In the meantime, af9260fb325ba31aff85f3d1c8f278f6c521d2db seems to be a usable workaround. But is that how it's supposed to be configured or just a misinterpretation of the warning/informational message?

ewolff commented 9 years ago

Good point. According to http://docs.vagrantup.com/v2/provisioning/basic_usage.html (see "Run Once or Always") this is expected behavior and makes some sense i.e. you probably don't want to run the provisioning once you do vagrant up because it will change the state of the machine i.e. recreate all Docker images. So I would rather not change this. You could use restart policies for Docker (see http://docs.docker.com/articles/host_integration/ and https://docs.docker.com/reference/commandline/cli/#restart-policies ) but if there is a problem the container would be restarted endlessly. So I am not sure what to do here. Suggestions?

Larzenegger commented 9 years ago

This restart policy sounds strange to me as well. It seems like "always" would be the option we'd want for restarting and this stackoverflow response also suggests that it would work.

My workaround was based on splitting your provisioning into two parts: The first part would (re)create all docker images and would only be executed once. The second part would have an "always" marker and contain all your run instructions.

It seems to start the containers as intended, but is there another downside to this approach?

ewolff commented 9 years ago

I think we should solve it as you suggest. Can you create a Pull Request? Thanks!

Larzenegger commented 9 years ago

Thanks for exploring this with me. :)