I use Docker provisioner for Vagrant. They say in the docs:
In addition to pulling images, the Docker provisioner can run and start containers for you. This lets you automatically start services as part of vagrant up.
Here's a part of my Vagrantfile:
config.vm.provision "docker" do |d|
d.run "jwilder/nginx-proxy",
args: "-v /var/run/docker.sock:/tmp/docker.sock:ro -v /vagrant/certs:/etc/nginx/certs -p 80:80 -p 443:443"
d.run "redis",
args: "-v /vagrant/data:/data"
...
end
But after vagrant halt
and then vagrant up
my containers are stopped.
$vagrant@vagrant-ubuntu-trusty-64:~$ docker ps -a
CONTAINER ID .. STATUS .. NAMES
6bb965d1a7b9 Exited (137) 2 days ago redis
7f45214f6f06 Exited (2) 2 days ago jwilder-nginx-proxy
Well, I didn't find the reason why Vagrant doesn't start containers on boot, but the workaround is to use Docker's restart policies. So, I updated my Vagrantfile, removed all the containers and did vagrant provision
to run containers again with new restart policies:
config.vm.provision "docker" do |d|
d.run "jwilder/nginx-proxy",
args: "--restart=always -v /var/run/docker.sock:/tmp/docker.sock:ro -v /vagrant/certs:/etc/nginx/certs -p 80:80 -p 443:443"
d.run "redis",
args: "--restart=always -v /vagrant/data:/data"
...
end
--restart=always
Always restart the container regardless of the exit status. When you specify always, the Docker daemon will try to restart the container indefinitely.
Now after vagrant halt
and then vagrant up
containers are started.