【Windows】VagrantでLinux(Ubuntu)環境を構築する
VirtualBoxのインストール
下記からインストーラーをダウンロードして、ウィザードに従ってインストールします。
Vagrantのインストール
下記からインストーラーをダウンロードして、ウィザードに従ってインストールします。
VagrantでLinux(Ubuntu)環境を作る
任意のフォルダを作成して、vagrantコマンドを3つ実行するだけです。
mkdir C:\work\vagrant\bionic64 cd C:\work\vagrant\bionic64 vagrant init hashicorp/bionic64 vagrant up vagrant ssh
実行結果はこんな感じです。
PS C:\work\vagrant\bionic64> vagrant init hashicorp/bionic64 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. PS C:\work\vagrant\bionic64> vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Box 'hashicorp/bionic64' could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: >= 0 ==> default: Loading metadata for box 'hashicorp/bionic64' default: URL: https://vagrantcloud.com/hashicorp/bionic64 ==> default: Adding box 'hashicorp/bionic64' (v1.0.282) for provider: virtualbox default: Downloading: https://vagrantcloud.com/hashicorp/boxes/bionic64/versions/1.0.282/providers/virtualbox.box default: ==> default: Successfully added box 'hashicorp/bionic64' (v1.0.282) for 'virtualbox'! ==> default: Importing base box 'hashicorp/bionic64'... ==> default: Matching MAC address for NAT networking... ==> default: Checking if box 'hashicorp/bionic64' version '1.0.282' is up to date... ==> default: Setting the name of the VM: bionic64_default_1635460439432_28479 ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... 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: Remote connection disconnect. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... default: The guest additions on this VM do not match the installed version of default: VirtualBox! In most cases this is fine, but in rare cases it can default: prevent things such as shared folders from working properly. If you see default: shared folder errors, please make sure the guest additions within the default: virtual machine match the version of VirtualBox you have installed on default: your host and reload your VM. default: default: Guest Additions Version: 6.0.10 default: VirtualBox Version: 6.1 ==> default: Mounting shared folders... default: /vagrant => C:/work/vagrant/bionic64 PS C:\work\vagrant\bionic64> vagrant ssh Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-58-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Thu Oct 28 22:36:38 UTC 2021 System load: 0.12 Processes: 92 Usage of /: 2.5% of 61.80GB Users logged in: 0 Memory usage: 11% IP address for eth0: 10.0.2.15 Swap usage: 0% * Super-optimized for small spaces - read how we shrank the memory footprint of MicroK8s to make it the smallest full K8s around. https://ubuntu.com/blog/microk8s-memory-optimisation 0 packages can be updated. 0 updates are security updates. vagrant@vagrant:~$
シャットダウンする場合は以下のコマンドを実行します。
vagrant halt