Mac上安装Docker

原创文章,转账请注明出自:http://blog.csdn.net/oopsoom/article/details/41785999

一、简介

  Docker是一个开源的容器引擎,能提供虚机化,从而达到隔离应用,可移植到任意安装有Docker的机器上运行,这对开发者来说是一个极大的福音。

  由于工作上原因,最近准备开始使用Docker(公司装Docker的时候,linux server内核版本太低,需要重新编译)。

  本文主要讲解如何在Mac OSX上安装Docker。

  

  Tips:由于Docker引擎是使用了特定于Linux内核的特性,所以需要安装一个轻量级的虚拟机(如VirtualBox)来在OSX上运行。

  所以需要下载官方提供的Boot2Docker来运行Docker守护进程。 

二、Docker安装

1. 安装 boot2docker/osx-installer

找到最新的Release版本点击下载,直接安装.

Mac上安装Docker_第1张图片

双击下载后的PKG包,进入安装向导:


安装完毕后,会发现你的Application里面多了2个程序:

这就是刚才我们提到的Boot2Docker和VM:

Mac上安装Docker_第2张图片

至此,安装步骤完毕。

三、配置启动Docker

在安装完毕后boot2docker后,就可以直接使用boot2docerk这个client command来操作vm中Images了。

1、boot2docker init 命令进行初始化

从日志可以看出,初始化的过程是下载一个boot2docer.iso,然后会用ssh生成用于docker的ssh的公钥和私钥对,用于远程。


[java] view plain copy 

  1. shengli-mac$ boot2docker init  

  2. Latest release for boot2docker/boot2docker is v1.3.2  

  3. Downloading boot2docker ISO image...  

  4. Success: downloaded https://github.com/boot2docker/boot2docker/releases/download/v1.3.2/boot2docker.iso  

  5. to /Users/shengli/.boot2docker/boot2docker.iso  

  6. Generating public/private rsa key pair.  

  7. Your identification has been saved in /Users/shengli/.ssh/id_boot2docker.  

  8. Your public key has been saved in /Users/shengli/.ssh/id_boot2docker.pub.  

  9. The key fingerprint is:  

  10. ff:7a:53:95:e6:44:27:70:e1:ac:0a:b5:02:35:72:29 shengli@192.168.2.101  

  11. The key's randomart image is:  

  12. +--[ RSA 2048]----+  

  13.   

  14. |      . +.  ..o. |  

  15.   

  16. |      E+..   +...|  

  17.   

  18. |      ..  .   +.o|  

  19.   

  20. |       . . . . +.|  

  21.   

  22. |        S . . +. |  

  23.   

  24. |         + .  .. |  

  25.   

  26. |          o  .   |  

  27.   

  28. |           .o    |  

  29.   

  30. |          .o..   |  

  31.   

  32. +-----------------+  

2、启动

boot2docerk start命令来启动


[java] view plain copy 

  1. shengli-mac$ boot2docker start  

  2. Waiting for VM and Docker daemon to start...  

  3. .......................ooooooooooooooooooo  

  4. Started.  

  5. Writing /Users/shengli/.boot2docker/certs/boot2docker-vm/ca.pem  

  6. Writing /Users/shengli/.boot2docker/certs/boot2docker-vm/cert.pem  

  7. Writing /Users/shengli/.boot2docker/certs/boot2docker-vm/key.pem  

  8.   

  9. To connect the Docker client to the Docker daemon, please set:  

  10.     export DOCKER_HOST=tcp://192.168.59.103:2376  

  11.     export DOCKER_CERT_PATH=/Users/shengli/.boot2docker/certs/boot2docker-vm  

  12.     export DOCKER_TLS_VERIFY=1  

Ps:这里HOST为192.168.59.103,这个就是以后要访问的虚拟机的地址。


[java] view plain copy 

  1. shengli-mac$ $(/usr/local/bin/boot2docker shellinit)  

  2. Writing /Users/shengli/.boot2docker/certs/boot2docker-vm/ca.pem  

  3. Writing /Users/shengli/.boot2docker/certs/boot2docker-vm/cert.pem  

  4. Writing /Users/shengli/.boot2docker/certs/boot2docker-vm/key.pem  

  5. shengli-mac$ docker version  

  6. Client version: 1.3.2  

  7. Client API version: 1.15  

  8. Go version (client): go1.3.3  

  9. Git commit (client): 39fa2fa  

  10. OS/Arch (client): darwin/amd64  

  11. Server version: 1.3.2  

  12. Server API version: 1.15  

  13. Go version (server): go1.3.3  

  14. Git commit (server): 39fa2fa  


至此,配置完毕。

如果想进入到虚拟机的控制台,可以使用boot2docker ssh命令


[java] view plain copy 

  1. shengli-mac$ boot2docker ssh  

  2.                         ##        .  

  3.                   ## ## ##       ==  

  4.                ## ## ## ##      ===  

  5.            /""""""""""""""""\___/ ===  

  6.       ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~  

  7.            \______ o          __/  

  8.              \    \        __/  

  9.               \____\______/  

  10.  _                 _   ____     _            _  

  11. | |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __  

  12. '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|  

  13. | |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |  

  14. |_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|  

  15. Boot2Docker version 1.3.2, build master : 495c19a - Mon Nov 24 20:40:58 UTC 2014  

  16. Docker version 1.3.2, build 39fa2fa  


四、第一个和第二个Docker程序

对于第一个,相信大家都很了解,Docker版的HelloWorld。这个正好来验证是否安装成功。

1. Docker HelloWorld

运行 docker run hello-world,docker会在本地查找镜像是否存在(肯定不存在了,刚装的= =), 然后docker会去远程Docker registry server去下载这个镜像。

下载后运行这个镜像。

这个镜像程序,会输出一句 Hello from Docker. 

如果看到这句话,说明你的Docker已经正确安装了。

[java] view plain copy 

  1. shengli-mac$ docker run hello-world  

  2. Unable to find image 'hello-world' locally  

  3. hello-world:latest: The image you are pulling has been verified  

  4. 511136ea3c5a: Pull complete   

  5. 7fa0dcdc88de: Pull complete   

  6. ef872312fe1b: Pull complete   

  7. Status: Downloaded newer image for hello-world:latest  

  8. Hello from Docker.  

  9. This message shows that your installation appears to be working correctly.  

  10.   

  11. To generate this message, Docker took the following steps:  

  12.  1. The Docker client contacted the Docker daemon.  

  13.  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.  

  14.     (Assuming it was not already locally available.)  

  15.  3. The Docker daemon created a new container from that image which runs the  

  16.     executable that produces the output you are currently reading.  

  17.  4. The Docker daemon streamed that output to the Docker client, which sent it  

  18.     to your terminal.  

  19.   

  20. To try something more ambitious, you can run an Ubuntu container with:  

  21.  $ docker run -it ubuntu bash  

  22.   

  23. For more examples and ideas, visit:  

  24.  http://docs.docker.com/userguide/  


运行后,该命令会listen监听访问,如果成功访问,则会看到nginx的log:

――EOF――


个人安装(version:1.8)遇到的问题:

>>>Please shutdown all running VirtualBox machines and exit VirtualBox then restart the installation.

   解决方法:

    ps aux | grep ‘VBoxHeadless'

    然后杀死其对应的进程id


你可能感兴趣的:(mac安装docker)