How can I start the provisioning of Docker via an external Dockerfile? My Vagrantfile looks like this at the moment
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.define :server_infrastructure do |t|
end
config.vm.provision "docker" do |d|
d.pull_images "ubuntu"
#how does the below work?
#d.build "new-container-name" "local-docker-file-name"
end
end
Your help is greatly appreciated
In addition to using orchestration tools like Ansible or Docker Compose, or your homegrown bubblegum and scripts with the docker command, you can use Vagrant to orchestrate Docker containers in a virtual guest system.
Provisioners in Vagrant allow you to automatically install software, alter configurations, and more on the machine as part of the vagrant up process. This is useful since boxes typically are not built perfectly for your use case.
The important difference between Vagrant vs. Docker is that Docker is used to create and run Linux containers, while Vagrant does the work to provision a machine with an operating system, a Docker installation and any other application that needs to run on the OS.
An option for the Docker provisioner to build images was added in v1.6.0. Download the latest version from the Vagrant website.
Once you've done that, put a Dockerfile next to your Vagrantfile. Add this to your Vagrantfile:
config.vm.provision "docker" do |d|
d.build_image "/vagrant", args: "-t my-name/my-new-image"
d.run "my-name/my-new-image"
end
Now your Docker image will be built and run with vagrant up
.
one workaround is through shell provisioning:
config.vm.provision "shell", inline: "docker build -t username/image /vagrant; docker run -d username/image"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With