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

[经验分享] Install Docker on Mac OS X(转)

[复制链接]
累计签到:5 天
连续签到:1 天
发表于 2015-12-30 09:39:41 | 显示全部楼层 |阅读模式
Install Docker on Mac OS X
  You can install Docker using Boot2Docker to run docker commands at your command-line. Choose this installation if you are familiar with the command-line or plan to contribute to the Docker project on GitHub.

  Alternatively, you may want to try Kitematic, an application that lets you set up Docker and run containers using a graphical user interface (GUI).

Command-line Docker with Boot2Docker
  Because the Docker daemon uses Linux-specific kernel features, you can't run Docker natively in OS X. Instead, you must install the Boot2Docker application. The application includes a VirtualBox Virtual Machine (VM), Docker itself, and the Boot2Docker management tool.
  The Boot2Docker management tool is a lightweight Linux virtual machine made specifically to run the Docker daemon on Mac OS X. The VirtualBox VM runs completely from RAM, is a small ~24MB download, and boots in approximately 5s.
  Requirements
  Your Mac must be running OS X 10.6 "Snow Leopard" or newer to run Boot2Docker.

Learn the key concepts before installing
  In a Docker installation on Linux, your machine is both the localhost and the Docker host. In networking, localhost means your computer. The Docker host is the machine on which the containers run.
  On a typical Linux installation, the Docker client, the Docker daemon, and any containers run directly on your localhost. This means you can address ports on a Docker container using standard localhost addressing such as localhost:8000 or 0.0.0.0:8376.

  In an OS X installation, the docker daemon is running inside a Linux virtual machine provided by Boot2Docker.

  In OS X, the Docker host address is the address of the Linux VM. When you start the boot2dockerprocess, the VM is assigned an IP address. Under boot2docker ports on a container map to ports on the VM. To see this in practice, work through the exercises on this page.

Install Boot2Docker


  •   Go to the boot2docker/osx-installer release page.

  •   Download Boot2Docker by clicking Boot2Docker-x.x.x.pkg in the "Downloads" section.

  •   Install Boot2Docker by double-clicking the package.
      The installer places Boot2Docker in your "Applications" folder.

  The installation places the docker and boot2docker binaries in your /usr/local/bin directory.

Start the Boot2Docker Application
  To run a Docker container, you first start the boot2docker VM and then issue docker commands to create, load, and manage containers. You can launch boot2docker from your Applications folder or from the command line.

  NOTE: Boot2Docker is designed as a development tool. You should not use it in production environments.


From the Applications folder
  When you launch the "Boot2Docker" application from your "Applications" folder, the application:


  •   opens a terminal window

  •   creates a $HOME/.boot2docker directory

  •   creates a VirtualBox ISO and certs

  •   starts a VirtualBox VM running the docker daemon

  Once the launch completes, you can run docker commands. A good way to verify your setup succeeded is to run the hello-world container.

    $ docker run hello-world
Unable to find image 'hello-world:latest' locally
511136ea3c5a: Pull complete
31cbccb51277: Pull complete
e45a5af57b00: Pull complete
hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
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 "hello-world" 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/
  A more typical way to start and stop boot2docker is using the command line.

From your command line
  Initialize and run boot2docker from the command line, do the following:


  •   Create a new Boot2Docker VM.

    $ boot2docker init
      This creates a new virtual machine. You only need to run this command once.

  •   Start the boot2docker VM.

    $ boot2docker start
  •   Display the environment variables for the Docker client.

    $ boot2docker shellinit
    Writing /Users/mary/.boot2docker/certs/boot2docker-vm/ca.pem
    Writing /Users/mary/.boot2docker/certs/boot2docker-vm/cert.pem
    Writing /Users/mary/.boot2docker/certs/boot2docker-vm/key.pem
    export DOCKER_HOST=tcp://192.168.59.103:2376
    export DOCKER_CERT_PATH=/Users/mary/.boot2docker/certs/boot2docker-vm
    export DOCKER_TLS_VERIFY=1
      The specific paths and address on your machine will be different.

  •   To set the environment variables in your shell do the following:

    $ eval "$(boot2docker shellinit)"
      You can also set them manually by using the export commands boot2docker returns.

  •   Run the hello-world container to verify your setup.

    $ docker run hello-world


Basic Boot2Docker Exercises
  At this point, you should have boot2docker running and the docker client environment initialized. To verify this, run the following commands:

$ boot2docker status
$ docker version
  Work through this section to try some practical container tasks using boot2docker VM.

Access container ports


  •   Start an NGINX container on the DOCKER_HOST.

    $ docker run -d -P --name web nginx
      Normally, the docker run commands starts a container, runs it, and then exits. The -d flag keeps the container running in the background after the docker run command completes. The -P flag publishes exposed ports from the container to your local host; this lets you access them from your Mac.

  •   Display your running container with docker ps command

    CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                                           NAMES
    5fb65ff765e9        nginx:latest        "nginx -g 'daemon of   3 minutes ago       Up 3 minutes        0.0.0.0:49156->443/tcp, 0.0.0.0:49157->80/tcp   web
      At this point, you can see nginx is running as a daemon.

  •   View just the container's ports.

    $ docker port web
    443/tcp -> 0.0.0.0:49156
    80/tcp -> 0.0.0.0:49157
      This tells you that the web container's port 80 is mapped to port 49157 on your Docker host.

  •   Enter the http://localhost:49157 address (localhost is 0.0.0.0) in your browser:

      This didn't work. The reason it doesn't work is your DOCKER_HOST address is not the localhost address (0.0.0.0) but is instead the address of the boot2docker VM.

  •   Get the address of the boot2docker VM.

    $ boot2docker ip
    192.168.59.103
  •   Enter the http://192.168.59.103:49157 address in your browser:

      Success!

  •   To stop and then remove your running nginx container, do the following:

    $ docker stop web
    $ docker rm web

Mount a volume on the container
  When you start boot2docker, it automatically shares your /Users directory with the VM. You can use this share point to mount directories onto your container. The next exercise demonstrates how to do this.


  •   Change to your user $HOME directory.

    $ cd $HOME
  •   Make a new site directory.

    $ mkdir site
  •   Change into the site directory.

    $ cd site
  •   Create a new index.html file.

    $ echo "my new site" > index.html
  •   Start a new nginx container and replace the html folder with your site directory.

    $ docker run -d -P -v $HOME/site:/usr/share/nginx/html --name mysite nginx
  •   Get the mysite container's port.

    $ docker port mysite
    80/tcp -> 0.0.0.0:49166
    443/tcp -> 0.0.0.0:49165
  •   Open the site in a browser:


  •   Try adding a page to your $HOME/site in real time.

    $ echo "This is cool" > cool.html
  •   Open the new page in the browser.


  •   Stop and then remove your running mysite container.

    $ docker stop mysite
    $ docker rm mysite

Upgrade Boot2Docker
  If you running Boot2Docker 1.4.1 or greater, you can upgrade Boot2Docker from the command line. If you are running an older version, you should use the package provided by the boot2docker repository.

From the command line
  To upgrade from 1.4.1 or greater, you can do this:


  •   Open a terminal on your local machine.

  •   Stop the boot2docker application.

    $ boot2docker stop
  •   Run the upgrade command.

    $ boot2docker upgrade

Use the installer
  To upgrade any version of Boot2Docker, do this:


  •   Open a terminal on your local machine.

  •   Stop the boot2docker application.

    $ boot2docker stop
  •   Go to the boot2docker/osx-installer release page.

  •   Download Boot2Docker by clicking Boot2Docker-x.x.x.pkg in the "Downloads" section.

  •   Install Boot2Docker by double-clicking the package.
      The installer places Boot2Docker in your "Applications" folder.


Learning more and Acknowledgement
  Use boot2docker help to list the full command line reference. For more information about using SSH or SCP to access the Boot2Docker VM, see the README at Boot2Docker repository.
  Thanks to Chris Jones whose blog inspired me to redo this page.
  Continue with the Docker User Guide.
  
  
  参考:https://docs.docker.com/installation/mac/
  http://dockerpool.com/static/books/docker_practice/appendix_command/README.html
  

运维网声明 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-158202-1-1.html 上篇帖子: WMware 10 上安装Mac OS X 10.9 系统的正确方法 下篇帖子: 在Mac OS X Snow Leopard中设置Google App Engine [失败]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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