How do I provision a Dockerfile from Vagrant

前端 未结 3 1278
Happy的楠姐
Happy的楠姐 2021-02-05 10:48

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         


        
3条回答
  •  孤城傲影
    2021-02-05 11:30

    For docker to build an image from a dockerfile, dockerfile in question must be presented in the guest machine and the way to ensure this is to use shared folder feature of vagrant.

    By default vagrant mounts your project root folder to the new vm under the name /vagrant. But in your case i suggest you share a different folder and put your dockerfiles there. Also by sharing a different folder you can make sure that your dockerfiles are seen read-only by the guest machine.

    Now suppose you create a new folder in your projects root directory named "docker" and put your dockerfiles in it. Now if you mount this folder to your guest machine and point docker to use that file you are all set. if you add these lines to your vagrant file it will work as expected. config.vm.synced_folder "docker/", "/docker_builds", create: true, mount_options: ["ro"] config.vm.provision "docker" do |d| d.build_image "/docker_builds", args: "-t my-name/my-new-image" d.run "my-name/my-new-image" end

提交回复
热议问题