安裝Docker

安裝Docker在各個環境上有不同的步驟,但在非Linux的系統上,就必須透過boot2docker來虛擬出可以執行Docker的環境。

Docker安裝的文件非常完整,在Docker的Installation Page有所有環境的安裝檔案與環境。

https://docs.docker.com/installation/

我們這邊說明一下boot2docker的安裝與基本使用方法...

下載與安裝boot2docker

boot2docker for Mac OS X的部分,下載可以在下面網址下載:

https://github.com/boot2docker/osx-installer/releases/latest

安裝的部分,只要透過安裝的Winzard完成安裝即可,在篇幅內就不再贅述安裝流程...

啟動與關閉boot2docker

啟動boot2docker

$ boot2docker start
Waiting for VM and Docker daemon to start...
.........................
Started.
Your DOCKER_HOST env variable is already set correctly.

當boot2docker啟動後,我們可以透過下面指令找到boot2docker的實際ip位置

$ boot2docker ip

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

以docker client而言,我們需要設定boot2docker環境變數,將docker host的位置指向server的位置

export DOCKER_HOST=tcp://192.168.59.103:2375

當設定完成,就可以透過docker的指令來操作...

$ docker info
Containers: 44
Images: 76
Storage Driver: aufs
 Root Dir: /mnt/sda1/var/lib/docker/aufs
 Dirs: 164
Execution Driver: native-0.2
Kernel Version: 3.16.1-tinycore64
Operating System: Boot2Docker 1.2.0 (TCL 5.3); 3.16.1-config-file : e75396e - Fri Aug 22 06:45:30 UTC 2014
Debug mode (server): true
Debug mode (client): false
Fds: 11
Goroutines: 11
EventsListeners: 0
Init Path: /usr/local/bin/docker
Username: peihsinsu
Registry: [https://index.docker.io/v1/]

當不需要boot2docker時候,我們可以透過下面指令關閉boot2docker環境

boot2docker stop

boot2docker有提供其他操作指令,我們可以透過help page來查詢其他可用的操作

透過-h可以得到boot2docker後面可以接受哪些參數操作

$ boot2docker -h
Usage of docker:
  --api-enable-cors=false                        Enable CORS headers in the remote API
  -D, --debug=false                              Enable debug mode
  -d, --daemon=false                             Enable daemon mode
  -G, --group="docker"                           Group to assign the unix socket specified by -H when running in daemon mode
                                                   use '' (the empty string) to disable setting of a group
  -H, --host=[]                                  The socket(s) to bind to in daemon mode
                                                   specified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd.
  --tls=false                                    Use TLS; implied by tls-verify flags
  --tlscacert="/Users/simonsu/.docker/ca.pem"    Trust only remotes providing a certificate signed by the CA given here
  --tlscert="/Users/simonsu/.docker/cert.pem"    Path to TLS certificate file
  --tlskey="/Users/simonsu/.docker/key.pem"      Path to TLS key file
  --tlsverify=false                              Use TLS and verify the remote (daemon: verify client, client: verify daemon)
  -v, --version=false                            Print version information and quit

另外,需要操作boot2docker的功能,可以透過boot2docker知道第二層指令有哪些...

$ 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.
   socket              Display the DOCKER_HOST socket to connect to.
   shellinit           Display the shell command 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 2375 in VM). (deprecated - use with care)
      --driver="virtualbox": hypervisor driver.
      --hostip=192.168.59.3: VirtualBox host-only network IP address.
      --iso="/Users/simonsu/.boot2docker/boot2docker.iso": path to 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.
      --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/simonsu/.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.
  -v, --verbose=false: display verbose command invocations.
      --vm="boot2docker-vm": virtual machine name.

另外,關於boot2docker的一些information,可以在boot2docker info中查詢到

$ boot2docker info | json
{
  "Name": "boot2docker-vm",
  "UUID": "e5f3e81c-f7c8-433c-97d6-958ebfedb788",
  "State": "running",
  "CPUs": 4,
  "Memory": 2048,
  "VRAM": 8,
  "CfgFile": "/Users/simonsu/VirtualBox VMs/boot2docker-vm/boot2docker-vm.vbox",
  "BaseFolder": "/Users/simonsu/VirtualBox VMs/boot2docker-vm",
  "OSType": "",
  "Flag": 0,
  "BootOrder": null,
  "DockerPort": 0,
  "SSHPort": 2022,
  "SerialFile": "/Users/simonsu/.boot2docker/boot2docker-vm.sock"
}

註:json這個指令是為了將screen output做json format的一個工具,如欲安裝json這個工具,可以參考jsontool

進入boot2docker Shell

到這邊,我們應該大概猜到,boot2docker其實是另外的一台VM,因此,應當也有進入這個VM的方法... 在Mac中,boot2docker是預設是安裝在VirtualBox中,如果要進到VM中,可以透過下面方法:

boot2docker ssh
                        ##        .
                  ## ## ##       ==
               ## ## ## ##      ===
           /""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
           \______ o          __/
             \    \        __/
              \____\______/
 _                 _   ____     _            _
| |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
boot2docker: 1.2.0
             3.16.1-config-file : e75396e - Fri Aug 22 06:45:30 UTC 2014
[email protected]:~$

進入boot2docker之後,一樣可以執行docker指令...

results matching ""

    No results matching ""