DevOps
  • DevOps
  • Docker
    • Overview
  • Vagrant
    • Overview
    • Installation
    • Basic Commands
    • Vagrantfile
      • Example
    • Deploying Multiple Machine
    • Distribution
    • Reference
  • Running SQL Server on Windows Docker
    • Introduction
      • Windows Container & Hyper-V Container
    • System Requirements and Prerequisites
    • Version Compatibility
    • Enable Hyper-V & Containers and Install Docker on Window Servers
    • Using Docker to Run MSSQL Image
    • Install SSMS for remoting MSSQL Server Image
    • Using Docker-Compose to Build Up a MSSQL Image
    • Increase the default Windows container's storage
    • Reference
    • Appendix
  • Kubernetes
    • Install Kubernetes with kubeasz
    • Use Hyper-V Manager to create VM for K8S
      • Specification of the VM
      • Use Hyper-V Manager to turn on a VM for K8S
    • Installation
      • Install VirtualBox and its extension on Ubuntu
      • Install kubectl
      • Install minikube
    • Getting Started
      • Running Kubernetes Locally via Minikube
    • Assign Memory Resources to Containers and Pods
    • Assign CPU Resources to Containers and Pods
    • Quality of Services (QoS)
    • Volume for Storage
      • Configure a Pod to Use a Volume for Storage
      • *Configure a Pod to Use a PersistentVolume for Storage
    • In a nutshell...
    • Reference
  • Ansible
    • What is Ansible?
    • Set Up OS Environments for Ansible
    • Install Ansible
    • Structure for ansible
      • Inventory
      • Playbook
      • Modules
      • Variables
      • Conditions
    • Security - Ansible Fault
    • 實際操作測試1 - 使用ssh
    • 實際操作測試2 - Docker容器部署
    • Appendix
    • Reference
  • Azure
    • Overview
    • Terms
    • Getting Started
    • Azure DevOps Services
    • Reference
Powered by GitBook
On this page
  • Run the specified box
  • Use vagrant identity to access Guest
  • Stop/Terminate the Guest
  • Box Management (vagrant box)
  • Snapshot Management (vagrant snapshot)
  • Configuration of VagrantFile

Was this helpful?

  1. Vagrant

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)

# 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)

# 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

PreviousInstallationNextVagrantfile

Last updated 6 years ago

Was this helpful?

vagrant box
vagrant snapshot