Basic Commands
Run the specified box
$ vagrant init ubuntu/xenial64
Use vagrant identity to access Guest
It use SSH key, as a result, no password is needed
$ vagrant ssh {NAME:Optional}
# 1. 正統登入法:用 vagrant 帳號 + vagrant 密碼來登入,並關閉 host key checking。
# 2. 正統登入法:用 vagrant 帳號 + private key 來登入,並關閉 host key checking。
# 3. 簡便登入法:用 vagrant ssh 指令登入。
# ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null vagrant@127.0.0.1 -p 2222
# password:vagrant
$ vagrant ssh-config
# Host default
# HostName 127.0.0.1
# User vagrant
# Port 2200
# UserKnownHostsFile /dev/null
# StrictHostKeyChecking no
# PasswordAuthentication no
# IdentityFile /root/.vagrant.d/insecure_private_key
# IdentitiesOnly yes
# LogLevel FATAL
# ssh vagrant@127.0.0.1 -p 2200 -i /root/.vagrant.d/insecure_private_key
Stop/Terminate the Guest
# After suspend, the container will be remained. Can uset `vagrant up` to bring it back
$ vagrant suspend # -f: force to shutdown
# To completely terminate and remove the guest
$ vagrant destroy
# Shut down/terminate the guest
$ vagrant halt
Box Management (vagrant box
)
vagrant box
)# Lists all the boxes that are installed into Vagrant
$ vagrant box list
# Directly down/add the box
$ vagrant box add
# Check if new version exist
$ vagrant box outdated
# Remove the old version
$ vagrant box prune
# Remove the box
$ vagrant box remove {NAME}
# Repackages the given box and puts it in the current directory so you can redistribute it
$ vagrant box repackage
# Updates the box for the current Vagrant environment if there are updates available.
$ vagrant box update
Snapshot Management (vagrant snapshot
)
vagrant snapshot
) # Takes a snapshot and pushes it onto the snapshot stack
$ vagrant snapshot push
# Restore the pushed state
$ vagrant snapshot pop
# --no-delete: Prevents deletion of the snapshot after restoring
# --no-start: Prevents the guest from being started after restore
# This command saves a new named snapshot. If this command is used, thepushandpopsubcommands cannot be safely used.
$ vagrant snapshot save [vm-name] {NAME}
# Restores the named snapshot
$ vagrant snapshot restore [vm-name] {NAME}
# --no-start: Prevents the guest from being started after restore
# List all the snapshots taken
$ vagrant snapshot list
# Delete the named snapshot
$ vagrant snapshot delete NAME
Configuration of VagrantFile
Last updated
Was this helpful?