LoginSignup
30
32

More than 5 years have passed since last update.

boot2dockerの使い方

Posted at

現状、Macでdockerを使うならboot2dockerが一番便利。

自分の中では、Tiny Core Linuxという軽量LinuxのVMを簡単なコマンドで設定して動かしてくれ、dockerコマンドをMacのターミナル上で直接打てるようにしてくれるものという理解。DockerはLinuxカーネルを前提にしているのでLinux以外のOSだとVM以外では動かないという問題を分かりやすく解決している。

インストール

以下を参考にインストールまたはアップデート
https://docs.docker.com/installation/mac/

$ boot2docker init

をすると必要な物がダウンロードされ、設定ファイルが~/.boot2docker/以下に作られる。

起動

$ boot2docker start

で、VMが立ち上がり、今後mac上でdockerコマンドが打てるようになる。

試しに、以下のコマンド等を試してみよう。

$ docker run hello-world
$ docker run -it ubuntu bash

ちなみに、boot2docker up, boot2docker bootも同じ意味。

逆に止める方法は以下の3種類のいずれかで可能。

$ boot2docker stop|down|halt

ネットワーク接続

boot2dockerは結局はvmで動かしているので、ネットワークを介してアクセスする時は注意が必要。たとえ、docker run -pオプションでポートを開放してもlocalhostにアクセスしても、何も起こらない。

$ boot2docker ip

The VM's Host only interface IP address is: 192.168.59.103

例えば、以下のコマンドでnginxを起動したら、

$ docker run --rm -i -t -p 80:80 nginx

この後ブラウザで、localhostにアクセスするのではなく、192.168.59.103にアクセスすれば、nginxのwelcome画面を見ることができる。

この部分は、特にLinux用に書かれたdockerのドキュメントを追っている時に注意が必要。

その他

他にもコマンドがいくつかあるが、大した数がないので自分で--helpなどを使い調べてみるとよい。infoとかは自分もよく使う。

$ boot2docker
Usage: boot2docker [<options>] {help|init|up|ssh|save|down|poweroff|reset|restart|config|status|info|ip|shellinit|delete|download|upgrade|version} [<args>]
$ boot2docker --help
Usage: boot2docker [<options>] <command> [<args>]

Boot2Docker management utility.

Commands:
   init                Create a new Boot2Docker VM.
   up|start|boot       Start VM from any states.
   ssh [ssh-command]   Login to VM via SSH.
   save|suspend        Suspend VM and save state to disk.
   down|stop|halt      Gracefully shutdown the VM.
   restart             Gracefully reboot the VM.
   poweroff            Forcefully power off the VM (may corrupt disk image).
   reset               Forcefully power cycle the VM (may corrupt disk image).
   delete|destroy      Delete Boot2Docker VM and its disk image.
   config|cfg          Show selected profile file settings.
   info                Display detailed information of VM.
   ip                  Display the IP address of the VM's Host-only network.
   shellinit           Display the shell commands to set up the Docker client.
   status              Display current state of VM.
   download            Download Boot2Docker ISO image.
   upgrade             Upgrade the Boot2Docker ISO image (restart if running).
   version             Display version information.

Options:
      --basevmdk="": Path to VMDK to use as base for persistent partition
      --dhcp=true: enable VirtualBox host-only network DHCP.
      --dhcpip=192.168.59.99: VirtualBox host-only network DHCP server address.
  -s, --disksize=20000: boot2docker disk image size (in MB).
      --dockerport=0: host Docker port (forward to port 2376 in VM). (deprecated - use with care)
      --driver="virtualbox": hypervisor driver.
      --hostip=192.168.59.3: VirtualBox host-only network IP address.
      --iso="/Users/aikawa/.boot2docker/boot2docker.iso": path to boot2docker ISO image.
      --iso-url="https://api.github.com/repos/boot2docker/boot2docker/releases": source URL to provision the boot2docker ISO image.
      --lowerip=192.168.59.103: VirtualBox host-only network DHCP lower bound.
  -m, --memory=2048: virtual machine memory size (in MB).
      --netmask=ffffff00: VirtualBox host-only network mask.
      --no-dummy="": Example parameter for the dummy driver.
      --retries=75: number of port knocking retries during 'start'
      --serial=false: try serial console to get IP address (experimental)
      --serialfile="": path to the serial socket/pipe.
      --ssh="ssh": path to SSH client utility.
      --ssh-keygen="ssh-keygen": path to ssh-keygen utility.
      --sshkey="/Users/aikawa/.ssh/id_boot2docker": path to SSH key to use.
      --sshport=2022: host SSH port (forward to port 22 in VM).
      --upperip=192.168.59.254: VirtualBox host-only network DHCP upper bound.
      --vbm="VBoxManage": path to VirtualBox management utility.
      --vbox-share=[]: (defaults to '/Users=Users' if no shares are specified; use 'disable' to explicitly prevent any shares from being created) List of directories to share during 'up|start|boot' via VirtualBox Guest Additions, with optional labels
  -v, --verbose=false: display verbose command invocations.
      --vm="boot2docker-vm": virtual machine name.
      --waittime=300: Time in milliseconds to wait between port knocking retries during 'start'
error in run: config error: pflag: help requested
30
32
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
30
32