❯ vagrant init --help
Usage: vagrant init [options] [name [url]]
Options:
(snip)
--template FILE Path to custom Vagrantfile template
vagrant init - Command-Line Interface | Vagrant | HashiCorp Developer
--template FILE- Provide a custom ERB template for generating the Vagrantfile.
この SO コメントが詳しい。
vagrant init と vagrant init -m で使われるデフォルトの Vagrantfile テンプレートは GitHub リポジトリにある。
これをコピーして改変したファイルを --template オプションで指定すれば良い。
❯ cat Vagrantfile.docker.erb
Vagrant.configure("2") do |config|
config.vm.box = "<%= box_name %>"
<% if box_version -%>
config.vm.box_version = "<%= box_version %>"
<% end -%>
<% if box_url -%>
config.vm.box_url = "<%= box_url %>"
<% end -%>
config.vm.provision "docker" do |d|
end
end
~/workspaces/vagrant-init-template-testing
❯ vagrant init --template Vagrantfile.docker.erb generic/ubuntu2204
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
~/workspaces/vagrant-init-template-testing
❯ cat Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "generic/ubuntu2204"
config.vm.provision "docker" do |d|
end
end