此文為講的是windows系統(tǒng)枢里,當系統(tǒng)為mac的OSX時,主要不同的是緩存位置苟耻。
緩存位置:
/Users/hu/.docker/machine/cache/boot2docker.iso
遠程地址用迅雷可下:
https://github.com/boot2docker/boot2docker/releases/download/v1.12.3/boot2docker.iso
下文為轉載:
在Windows中安裝Docker需要注意的是:
1靶擦、 必須是64位操作系統(tǒng)
2监徘、 已正確開啟系統(tǒng)虛擬化
3牍氛、 在Windows系統(tǒng)中安裝Docker一般僅限于測試階段,實際的應用最好還是安裝在Linux操作系統(tǒng)中增炭,具體安裝方法可參照文檔《Centos 6.4中安裝Docker》
檢查是否已開啟系統(tǒng)虛擬化
Ctrl+Alt+Delete 打開任務管理器 –> 選擇性能選項卡即可看到虛擬化的狀態(tài)忍燥,在虛擬化后面跟的是已啟用則表示已正常開啟,否則未開啟隙姿。
開啟虛擬化的方法:
開機進入BIOS 選擇Advanced選項卡 設置Secure Virtual Machine Mode為Enabled 版本注意
進入官網(wǎng) www.docker.com梅垄,點擊Download Docker for Windows 即可下載Windows的安裝組件,需要注意的是這里下載的Docker不可以安裝到Windows8的系統(tǒng)上输玷,此安裝程序的最低要求是Windows10队丝。
借助Docker Toolbox
下載Docker Toolbox靡馁,這里可以選擇蘋果和Windows兩個版本,現(xiàn)在下載Windows版本的Docker Toolbox机久,下載下來的文件名是:DockerToolbox-1.11.2.exe 臭墨,版本號可能有所不同。
安裝Docker Toolbox
安裝Docker Toolbox和安裝其他Windows程序一樣膘盖,都是比較單純的下一步胧弛。具體步驟也可以參考官方提供的【Install Docker for Windows】這篇文檔
創(chuàng)建Docker主機
安裝完Docker Toolbox后需要創(chuàng)建一個Docker的虛擬主機才能正常使用Docker服務。
可以借助docker-machine命令來完成Docker虛擬主機的相關操作:
help 查看幫助信息
active 查看活動的Docker主機
config 輸出連接的配置信息
create 創(chuàng)建一個Docker主機
env 顯示連接到某個主機需要的環(huán)境變量
inspect 輸出主機更新信息
ip 獲取Docker主機地址
kill 停止某個Docker主機
ls 列出所有管理的Docker主機
regenerate-certs 為某個主機重新成功TLS認證信息
restart 重啟Docker主機
rm 刪除Docker主機
scp 在Docker主機之間復制文件
ssh SSH到主機上執(zhí)行命令
start 啟動一個主機
status 查看一個主機狀態(tài)
stop 停止一個主機
upgrade 更新主機Docker版本為最新
url 獲取主機的URL
創(chuàng)建Docker虛擬主機衔憨,并指定名稱為default
docker-machine create -d virtualbox default
當出現(xiàn):
Running pre-create checks...
(default) No default Boot2Docker ISO found locally, downloading the latest release...
(default) Latest release for github.com/boot2docker/boot2docker is v1.12.1
(default) Downloading C:\Users\zsl-pc.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v1.12.1/boot2docker.iso...
表示正在下載boot2docker.iso鏡像文件叶圃,這個速度會非常慢袄膏,這時可以先按Ctrl+C取消安裝践图,把boot2docker.iso文件通過迅雷等下載工具下載下來并放到指定目錄(C:\Users\zsl-pc.docker\machine\cache\,此目錄在不同電腦上會有所不同)下再安裝沉馆。再次運行create創(chuàng)建Docker虛擬主機時就不會再去遠程下載码党,而是使用本地的iso文件了。
從這里可以看出斥黑,docker-machine實際是安裝了一個虛擬機揖盘,跟VMware非常相似,只是這個更輕量級锌奴。
安裝完成后可以看到:
F:\java\Docker>docker-machine create -d virtualbox default
Running pre-create checks...
Creating machine...
(default) Copying C:\Users\zsl-pc.docker\machine\cache\boot2docker.iso to C:\Users\zsl-pc.docker\machine\machines\default\boot2docker.iso...
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting the VM...
(default) Check network to re-create if needed...
(default) Windows might ask for the permission to create a network adapter. Sometimes, such confirmation window is minimized in the taskbar.
(default) Found a new host-only adapter: "VirtualBox Host-Only Ethernet Adapter #2"
(default) Windows might ask for the permission to configure a network adapter. Sometimes, such confirmation window is minimized in the taskbar.
(default) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env default
可使用命令docker-machine ls查看存在的Docker虛擬主機:
F:\java\Docker>docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default - virtualbox Running tcp://192.168.99.100:2376 v1.12.1
設置Docker環(huán)境
當運行命令docker images查看本地鏡像時出提示:
F:\java\Docker>docker images
An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/images/json: open //./pipe/docker_engine: The system cannot find the file specified.
說明Docker-machine的環(huán)境沒有配置好兽狭。
命令docker-machine env default,注意default是docker的主機名稱鹿蜀,可以使用docker-machine ls查看箕慧。
F:\java\Docker>docker-machine env default
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=C:\Users\zsl-pc.docker\machine\machines\default
SET DOCKER_MACHINE_NAME=default
REM Run this command to configure your shell:
REM @FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i
F:\java\Docker>@FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i
注意上面是兩個命令:
docker-machine env default
@FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i
上面的default都是Docker的主機名稱。
測試Docker
通過上面幾個步驟已經(jīng)完成Docker在Windows8中的安裝茴恰,現(xiàn)在使用命令docker run hello-world運行一個hello-world的測試容器:
F:\java\Docker>docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
- The Docker client contacted the Docker daemon.
- The Docker daemon pulled the "hello-world" image from the Docker Hub.
- The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading. - The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker Hub account:
https://hub.docker.com
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
只要出現(xiàn)上面的信息就表示Docker已經(jīng)正常安裝成功颠焦!