Skip to content

Instantly share code, notes, and snippets.

@0ta2
Last active October 31, 2016 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0ta2/0a96322fc3927501e34d to your computer and use it in GitHub Desktop.
Save 0ta2/0a96322fc3927501e34d to your computer and use it in GitHub Desktop.
Vagrantコマンドのチートシート ref: http://qiita.com/sabakan7/items/69c2378600bf8adaac5c
# vagrant COMMAND -h
$ vagrant -h
$ vagrant --version
Vagrant 1.8.6
### --versionは省略できる
$ vagrant -v
Vagrant 1.7.4
### バージョン情報を確認するに加えて、最新版かどうかも確認してくれる
$ vagrant version
Installed Version: 1.8.6
Latest Version: 1.8.6
You're running an up-to-date version of Vagrant!
### 構文 vagrant destroy [options] [name]
$ vagrant destroy
$ vagrant destroy default
# Vagrantは仮想マシンを複数台起動することができるため1台だけ廃棄する場合は、仮想マシン名を指定する必要がある。上記は、「default」という仮想マシンだけ廃棄
### 構文 vagrant status [name]
$ vagrant share
Current machine states:
default not created (virtualbox)
### 構文 vagrant status [id]
$ vagrant global-status
id name provider state directory
------------------------------------------------------------------------------------
30f884a server1 virtualbox running /Users/ghfdjk/Desktop/sabakan7-vagrant-a77e0e59c708
The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date. To interact with any of the machines, you can go to
that directory and run Vagrant, or you can use the ID directly
with Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"
#### vagrant ssh [options] [name]
$ vagrant ssh
$ vagrant ssh default
# Vagrantは仮想マシンを複数台起動している場合は、仮想マシン名を指定する必要がある。上記は、「default」という仮想マシンに接続している
### 構文 vagrant ssh-config [options] [name]
$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/hogehoge/centos7/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
# vagrantにsshする際の必要な情報を表示します
### 接続を便利にするのために
$ vagrant ssh-config >> ~/.ssh/config
# 上記のコマンドでsshのconfigファイルに追記してくれる。そうすると下記の様に「ssh default」で接続ができるようになる
$ ssh default
[vagrant@localhost ~]$
### 今度追記予定
connect
help
login
package
plugin
provision
push
rdp
resume
suspend
### 構文 vagrant box add [options] <name, url, or path> <url>
$ vagrant box add ghfdjk/centos7
# Atlasからboxを持ってくると、name, urlは特に意識する必要はありません。
# nameは、box作成者が指定しているので、意識する必要はないです。
### URLからboxを追加
$ vagrant box add sample https://atlas.hashicorp.com/ghfdjk/boxes/centos7/versions/1.1/providers/virtualbox.box
# sampleというbox名(任意)とboxファイルのURLを指定する
### ローカルのboxファイルを追加
$ vagrant box add sample package.box
# package.boxというファイルが同一ディレクトリがある場合
### 構文 vagrant box list [options]
$ vagrant box list [options]
bento/centos-6.7 (virtualbox, 2.2.2)
mackerel/centos66 (virtualbox, 0.0.2)
mackerel/centos7 (virtualbox, 0.0.1)
### 構文 vagrant box remove <name>
$ vagrant box remove mackerel/centos7
Removing box 'mackerel/centos7' (v0.0.1) with provider 'virtualbox'...
### 構文 vagrant box repackage <name> <provider> <version>
$ vagrant box repackage mackerel/centos66 virtualbox 0.0.2
# provide VirtualBoxを使用しているので指定する。
# バージョンが0.0.2なので指定する
# repackageすると、addした時点での状態をpackage.boxとして出力してくれる
### vagrant init [name [url]]
### name指定
$ vagrant init mackerel/centos66 # nameの部分は、ユーザ名/box名というような表記となっています。
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.
#### initをするとVagrantfileが生成されて、nameの部分が下記のようになって生成されます。
$ grep "mackerel/centos66" Vagrantfile
config.vm.box = "mackerel/centos66"
#### 引数のnameは[]のため省略は可能です。ですが省略すると「base」という名前生成されます。
$ grep "config.vm.box" Vagrantfile
config.vm.box = "base"
### 構文 vagrant up [options] [name]
$ vagrant up
### 複数起動している場合
$ vagrant up default
# Vagrantは仮想マシンを複数台起動することができるため1台だけ起動する場合は、仮想マシン名を指定する必要がある。上記は、「default」という仮想マシンだけ起動
### 構文 vagrant halt [options] [name]
$ vagrant halt
### 複数台起動している場合
$ vagrant halt default
# Vagrantは仮想マシンを複数台起動することができるため1台だけ停止する場合は、仮想マシン名を指定する必要がある。上記は、「default」という仮想マシンだけ停止
### 構文 vagrant reload [vm-name]
$ vagrant reload
# reloadは、Vagrantfileを再読み込みが発生するため、変更をした場合は、reloadを実行する。
### 複数起動している場合
$ vagrant reload default
# Vagrantは仮想マシンを複数台起動することができるため1台だけ再起動する場合は、仮想マシン名を指定する必要がある。上記は、「default」という仮想マシンだけ再起動
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment