VagrantとDockerについて動作確認

投稿者: | 2018/03/07

VagrantとDockerについて名前しか知らなかったので試した
を参考にvagrant入れてみた

まずはインストール。
VirtualBoxインストール
Vagrantインストール
再起動が必要かも。

コマンドプロンプトを開いてインストール確認。

>vagrant -v
Vagrant 2.0.2

早速Vagrantを動かしてみる。

>mkdir C:\workspace\vagrant
>cd C:\workspace\vagrant
>vagrant init
>vagrant box add bento/centos-6.7
==> box: Loading metadata for box 'bento/centos-6.7'
    box: URL: https://vagrantcloud.com/bento/centos-6.7
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) parallels
2) virtualbox
3) vmware_desktop

Enter your choice: 2
==> box: Adding box 'bento/centos-6.7' (v2.2.7) for provider: virtualbox
    box: Downloading: https://vagrantcloud.com/bento/boxes/centos-6.7/versions/2.2.7/providers/virtualbox.box
    box: Progress: 100% (Rate: 1251k/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'bento/centos-6.7' (v2.2.7) for 'virtualbox'!

vagrantfileを編集

  # どのboxを使うか
  config.vm.box = "bento/centos-6.7"
  # 使用するIPアドレスを設定
  config.vm.network "private_network", ip: "192.168.33.10"

そして起動。

>vagrant up

ここで何も起こらず困ったので調べるとどうやらWindows7 + Vagrantでは問題が起こるようです。
解決方法もあるので参考に。

Vagrant up から進まない!?

再度試みる・・

>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'bento/centos-6.7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'bento/centos-6.7' is up to date...
==> default: Setting the name of the VM: vagrant_default_1519797864247_61297
Vagrant is currently configured to create VirtualBox synced folders with
the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant
guest is not trusted, you may want to disable this option. For more
information on this option, please refer to the VirtualBox manual:

  https://www.virtualbox.org/manual/ch04.html#sharedfolders

This option can be disabled globally with an environment variable:

  VAGRANT_DISABLE_VBOXSYMLINKCREATE=1

or on a per folder basis within the Vagrantfile:

  config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlinksCreate: false
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> 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: Connection reset. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection aborted. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Connection aborted. Retrying...
    default: Warning: Connection reset. Retrying...
    default: Warning: Connection aborted. 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: 5.0.20
    default: VirtualBox Version: 5.2
==> default: Configuring and enabling network interfaces...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Mounting shared folders...
    default: /vagrant => C:/workspace/testprogram/vagrant

成功!これでsshでログインできる状態になりました。
vagrant sshで接続しても良いし、Vagrantfileに記載したIPアドレス「192.168.33.10」へなんかのツールからアクセスしてもいけます。

最後にシャットダウンするには

>vagrant halt

消してやり直したいなら

>vagrant destroy

こりゃ楽だ。こういう敷居を下げてくれるツールは本当に助かる。


コメントを残す

メールアドレスが公開されることはありません。