A good advantage of using vagrant is that you can share our Box in collaboration

Pack

Let's introduce the packaging method below

First determine which virtual machine needs to be packaged, and enter the installation directory where VirtualBox is installed

The default is in this path C:\Program Files\Oracle\VirtualBox
cd "C:\Program Files\Oracle\VirtualBox"

Check all the virtual machines, you can see the display format is as follows: "vmname" {vmid} , what we need here is vmname

> ./VBoxManage.exe list vms
"django-twitter_default_1619620682201_12310" {b3c74405-5d50-4f05-9f0e-98c9563f1fa5}

Change the target to the path you need, and then execute the following directory

vagrant package --base django-twitter_default_1619620682201_12310 --output demo_ubuntu18.box

Well, at this time, a file of demo_ubuntu18.box

Use a packaged image

Packaging alone is not enough, because the purpose of packaging is to use box mirroring. There are two points to note when using, that is because of the ssh key, you will find that you can’t get in after adding and then up. This is because you need to modify the vagrantfile file and change the default key login to the account password. Log in.

The ssh key error is as follows

> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'hashicorp/bionic64_demo_ubuntu18'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: twitter-term-1_default_1623336326135_46711
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: You are trying to forward to privileged ports (ports <= 1024). Most
==> default: operating systems restrict this to only privileged process (typically
==> default: processes running as an administrative user). This is a warning in case
==> default: the port forwarding doesn't work. If any problems occur, please try a
==> default: port higher than 1024.
==> default: Forwarding ports...
    default: 8000 (guest) => 80 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
But account password login is not as secure as key login, so after the first login (account + password), it is recommended to change to key login

config.ssh.username="xxxx"
config.ssh.password="xxxx"

initialization

If you do not have the vagrantfile file, you only need to initialize

You can reuse the vagrantfile file of the old virtual machine, or perform the initialization operation to create a new vagrantfile file
vagrant init [box_name]

Add box

vagrant box add {box_name} {box_file_path}

Reference article:

Use vagrant packaging system-make your own box
Vagrant+Miniconda+PyCharm
Vagrant ssh authentication failure
"Warning: Authentication failure. Retrying... " after packaging box #5186


universe_king
3.5k 声望716 粉丝

引用和评论

0 条评论