VirtualBox Port Forwarding Using Packer

I am creating a VirtualBox image using Packer .

Then I start the virtual machine, and I would like to use ssh to connect to it. I know how to enable port forwarding using the GUI , but I prefer to automate things, so I'm looking for a way to let Packer do this for me.

I use NAT as a way to connect my virtual machine to the network.

How can I tell Packer to forward some ports to the VM?

+4
source share
2 answers

, VirtualBox VBoxManage, packerConfig.json

"type": "virtualbox-iso",
"vboxmanage": [
   [ "modifyvm", "{{.Name}}", "--memory", "1024" ],
   [ "modifyvm", "{{.Name}}", "--cpus", "1" ],
   [ "modifyvm", "{{.Name}}", "--natpf1", "guest_ssh,tcp,,3022,,22" ]
 ]
...

VirtualBox 3022 22.

, ssh -p 3022 me@127.0.0.1 .

+5

VirtualBox Packer, :

     [
         "modifyvm", "{{.Name}}", "--natpf1", "name,tcp,ipHost,portHost,IpGuest,PortGuest"
     ]
0

Source: https://habr.com/ru/post/1570148/


All Articles