设为首页 收藏本站
查看: 1147|回复: 0

[经验分享] Docker 安装 on Mac OS X

[复制链接]

尚未签到

发表于 2015-10-13 12:05:12 | 显示全部楼层 |阅读模式
一、简介
  Docker是一个开源的容器引擎,能提供虚机化,从而达到隔离应用,可移植到任意安装有Docker的机器上运行,这对开发者来说是一个极大的福音。
  由于工作上原因,最近准备开始使用Docker(公司装Docker的时候,linux server内核版本太低,需要重新编译)。
  本文主要讲解如何在Mac OSX上安装Docker。
  
  Tips:由于Docker引擎是使用了特定于Linux内核的特性,所以需要安装一个轻量级的虚拟机(如VirtualBox)来在OSX上运行。
  所以需要下载官方提供的Boot2Docker来运行Docker守护进程。
二、Docker安装
1. 安装 boot2docker/osx-installer
找到最新的Release版本,https://github.com/boot2docker/osx-installer/releases, 下载PKG,直接安装.
DSC0000.jpg
  双击下载后的PKG包,进入安装向导:
DSC0001.jpg

  安装完毕后,会发现你的Application里面多了2个程序:
  这就是刚才我们提到的Boot2Docker和VM:
DSC0002.jpg

  至此,安装步骤完毕。
三、配置启动Docker
在安装完毕后boot2docker后,就可以直接使用boot2docerk这个client command来操作vm中Images了。1、boot2docker init 命令进行初始化
  从日志可以看出,初始化的过程是下载一个boot2docer.iso,然后会用ssh生成用于docker的ssh的公钥和私钥对,用于远程。
  
shengli-mac$ boot2docker init
Latest release for boot2docker/boot2docker is v1.3.2
Downloading boot2docker ISO image...
Success: downloaded https://github.com/boot2docker/boot2docker/releases/download/v1.3.2/boot2docker.iso
to /Users/shengli/.boot2docker/boot2docker.iso
Generating public/private rsa key pair.
Your identification has been saved in /Users/shengli/.ssh/id_boot2docker.
Your public key has been saved in /Users/shengli/.ssh/id_boot2docker.pub.
The key fingerprint is:
ff:7a:53:95:e6:44:27:70:e1:ac:0a:b5:02:35:72:29 shengli@192.168.2.101
The key's randomart image is:
+--[ RSA 2048]----+
|      . +.  ..o. |
|      E+..   +...|
|      ..  .   +.o|
|       . . . . +.|
|        S . . +. |
|         + .  .. |
|          o  .   |
|           .o    |
|          .o..   |
+-----------------+2、启动
  boot2docerk start命令来启动
  
shengli-mac$ boot2docker start
Waiting for VM and Docker daemon to start...
.......................ooooooooooooooooooo
Started.
Writing /Users/shengli/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/shengli/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/shengli/.boot2docker/certs/boot2docker-vm/key.pem
To connect the Docker client to the Docker daemon, please set:
export DOCKER_HOST=tcp://192.168.59.103:2376
export DOCKER_CERT_PATH=/Users/shengli/.boot2docker/certs/boot2docker-vm
export DOCKER_TLS_VERIFY=1  Ps:这里HOST为192.168.59.103,这个就是以后要访问的虚拟机的地址。
  
shengli-mac$ $(/usr/local/bin/boot2docker shellinit)
Writing /Users/shengli/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/shengli/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/shengli/.boot2docker/certs/boot2docker-vm/key.pem
shengli-mac$ docker version
Client version: 1.3.2
Client API version: 1.15
Go version (client): go1.3.3
Git commit (client): 39fa2fa
OS/Arch (client): darwin/amd64
Server version: 1.3.2
Server API version: 1.15
Go version (server): go1.3.3
Git commit (server): 39fa2fa  
  至此,配置完毕。
  如果想进入到虚拟机的控制台,可以使用boot2docker ssh命令
  shengli-mac$ boot2docker ssh
##        .
## ## ##       ==
## ## ## ##      ===
/""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
\______ o          __/
\    \        __/
\____\______/
_                 _   ____     _            _
| |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.3.2, build master : 495c19a - Mon Nov 24 20:40:58 UTC 2014
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已经正确安装了。shengli-mac$ docker run hello-world
Unable to find image 'hello-world' locally
hello-world:latest: The image you are pulling has been verified
511136ea3c5a: Pull complete
7fa0dcdc88de: Pull complete
ef872312fe1b: Pull complete
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:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the &quot;hello-world&quot; image from the Docker Hub.
(Assuming it was not already locally available.)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. 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
For more examples and ideas, visit:
http://docs.docker.com/userguide/2、Docker Nginx
这里会演示下载一个Nginx Server的镜像,然后可以通过本机访问Docker的容器端口,从而访问到部署在Docker中的Nginx。
docker run --rm -i -t -p 80:80 nginxshengli-mac$ docker run --rm -i -t -p 80:80 nginx
Unable to find image 'nginx' locally
nginx:latest: The image you are pulling has been verified
f10807909bc5: Pull complete
f6fab3b798be: Pull complete
d21beea329f5: Pull complete
04499cf33a0e: Pull complete
34806d38e48d: Pull complete
343c8475e349: Pull complete
92360dceda1a: Pull complete
9495a555677d: Pull complete
911e2df03930: Pull complete
88daddf047c6: Pull complete
db8a64f62509: Pull complete
e46b3488b010: Pull complete
511136ea3c5a: Already exists
Status: Downloaded newer image for nginx:latest
运行后,该命令会listen监听访问,如果成功访问,则会看到nginx的log: DSC0003.jpg
192.168.59.3 - - [07/Dec/2014:02:24:06 +0000] &quot;GET / HTTP/1.1&quot; 200 612 &quot;-&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36&quot; &quot;-&quot;
2014/12/07 02:24:06 [error] 7#0: *1 open() &quot;/usr/share/nginx/html/favicon.ico&quot; failed (2: No such file or directory), client: 192.168.59.3, server: localhost, request: &quot;GET /favicon.ico HTTP/1.1&quot;, host: &quot;192.168.59.103&quot;
192.168.59.3 - - [07/Dec/2014:02:24:06 +0000] &quot;GET /favicon.ico HTTP/1.1&quot; 404 570 &quot;-&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36&quot; &quot;-&quot;
将nginx镜像运行在Docker的80端口,那么你访问DOCKER_HOST:80将会看到nginx的欢迎页面。
如果你忘记了dock的host,可以使用:boot2docker ipshengli-mac$ boot2docker ip
The VM's Host only interface IP address is: 192.168.59.103五、总结
  本文讲解了,如何在Mac OSX安装和部署Docker,没有特别难的步骤,VM启动也是后台进程,很轻量级。
  
/Applications/VirtualBox.app/Contents/MacOS/VBoxHeadless --comment boot2docker-vm --startvm 89b84e20-fd75-4ae6-a437-c3b2778aeed1 --vrde config
  ——EOF——
  参考:https://docs.docker.com/installation/mac/
  原创文章,转账请注明出自:http://blog.iyunv.com/oopsoom/article/details/41785999

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-126256-1-1.html 上篇帖子: Actor Platform 平台搭建(一) -平台介绍-Docker搭建方法 下篇帖子: centos 7安装docker
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表