Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I provision a Dockerfile from Vagrant

Tags:

docker

vagrant

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

like image 1000
robkuz Avatar asked Jan 16 '14 16:01

robkuz


People also ask

Can Vagrant manage docker containers?

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.

What is Vagrant provisioning?

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.

Do you need Vagrant with docker?

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.


2 Answers

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.

like image 106
Rohan Singh Avatar answered Oct 11 '22 12:10

Rohan Singh


one workaround is through shell provisioning:

config.vm.provision "shell", inline: "docker build -t username/image /vagrant; docker run -d username/image"
like image 23
defvol Avatar answered Oct 11 '22 12:10

defvol