ewolff/microservice

Vagrantfile run directives only executed during provisioning

Larzenegger opened this issue · 4 comments

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, af9260f 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?

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?

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?

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

Thanks for exploring this with me. :)