16
17

More than 5 years have passed since last update.

boot2docker にホストオンリーアダプターを追加する

Last updated at Posted at 2014-05-18

2014.09.15 追記

最新のバージョンでは、デフォルトでホストオンリーアダプターが追加になったようです。このため、本記事のような作業は不要となりました。
ホストオンリーアダプターの IPアドレスは、以下のコマンドで確認できます。

boot2docker ip

ref: https://github.com/boot2docker/boot2docker#container-port-redirection

Container Port redirection

The latest version of boot2docker sets up two network adaptors, one using NAT to allow the VM to download images and files from the internet, and a host only network that Docker container's ports will be exposed on.


boot2docker で作成される VM は、NAT アダプタしか追加されないため、MAC 上からは、直接アクセスできない。

このため、VM <-> MAC 間の通信が可能な ホストオンリーアダプターを追加してみる。

追加

  1. VM(boot2docker) が起動していれば、停止。いなければ作成

    boot2docker stop
    or
    boot2docker init
    
  2. ホストオンリーネットワーク(10.10.10.0/24)を新規に追加する。

    hostonlyif="vboxnet$(VBoxManage list hostonlyifs|grep -c ^Name)"
    VBoxManage hostonlyif create
    VBoxManage hostonlyif ipconfig $hostonlyif --ip 10.10.10.1 --netmask 255.255.255.0
    
    • 上記を実行すると MAC 上に 10.10.10.1 の IP が振られる
  3. 作成したホストオンリーネットワークに DHCP を追加

    VBoxManage dhcpserver add --ifname $hostonlyif --ip 10.10.10.2 --netmask 255.255.255.0 --lowerip 10.10.10.10 --upperip 10.10.10.10 --enable
    
    • lowerip と upperip を同じにしているので、VM(boot2docker) に振られる IPアドレスは10.10.10.10となる
    • VBoxManage: error: DHCP server already exists となった場合は、すでに DHCPサーバが存在しているので、上記コマンドの addmodify に変更して実行する。
  4. VM に上記ネットワークに属する NIC を追加

    VBoxManage modifyvm boot2docker-vm --nic2 hostonly --nictype2 virtio --hostonlyadapter2 $hostonlyif
    

削除

  1. 作成状況の確認

    VBoxManage list hostonlyifs
    VBoxManage list dhcpservers
    
  2. VM からホストオンリーアダプターを削除

    VBoxManage modifyvm boot2docker-vm --nic2 none
    
  3. DHCP と ホストオンリーネットワークの削除

    VBoxManage dhcpserver remove --netname HostInterfaceNetworking-$hostonlyif
    VBoxManage hostonlyif remove $hostonlyif
    
16
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
17