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

  1. Go to the boot2docker/osx-installerrelease page.

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

  3. 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.

  1. $ docker run hello-world
  2. Unable to find image 'hello-world:latest' locally
  3. 511136ea3c5a: Pull complete
  4. 31cbccb51277: Pull complete
  5. e45a5af57b00: Pull complete
  6. 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.
  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. To generate this message, Docker took the following steps:
  11. 1. The Docker client contacted the Docker daemon.
  12. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  13. (Assuming it was not already locally available.)
  14. 3. The Docker daemon created a new container from that image which runs the
  15. executable that produces the output you are currently reading.
  16. 4. The Docker daemon streamed that output to the Docker client, which sent it
  17. to your terminal.
  18. To try something more ambitious, you can run an Ubuntu container with:
  19. $ docker run -it ubuntu bash
  20. For more examples and ideas, visit:
  21. 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:

  1. Create a new Boot2Docker VM.

    1. $ boot2docker init

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

  2. Start the boot2docker VM.

    1. $ boot2docker start
  3. Display the environment variables for the Docker client.

    1. $ boot2docker shellinit
    2. Writing /Users/mary/.boot2docker/certs/boot2docker-vm/ca.pem
    3. Writing /Users/mary/.boot2docker/certs/boot2docker-vm/cert.pem
    4. Writing /Users/mary/.boot2docker/certs/boot2docker-vm/key.pem
    5. export DOCKER_HOST=tcp://192.168.59.103:2376
    6. export DOCKER_CERT_PATH=/Users/mary/.boot2docker/certs/boot2docker-vm
    7. export DOCKER_TLS_VERIFY=1

    The specific paths and address on your machine will be different.

  4. To set the environment variables in your shell do the following:

    1. $ eval "$(boot2docker shellinit)"

    You can also set them manually by using the export commands boot2docker returns.

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

    1. $ 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:

  1. $ boot2docker status
  2. $ docker version

Work through this section to try some practical container tasks using boot2docker VM.

Access container ports

  1. Start an NGINX container on the DOCKER_HOST.

    1. $ 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.

  2. Display your running container with docker ps command

    1. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    2. 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.

  3. View just the container's ports.

    1. $ docker port web
    2. 443/tcp -> 0.0.0.0:49156
    3. 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.

  4. 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.

  5. Get the address of the boot2docker VM.

    1. $ boot2docker ip
    2. 192.168.59.103
  6. Enter the http://192.168.59.103:49157 address in your browser:

    Success!

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

    1. $ docker stop web
    2. $ 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.

  1. Change to your user $HOME directory.

    1. $ cd $HOME
  2. Make a new site directory.

    1. $ mkdir site
  3. Change into the site directory.

    1. $ cd site
  4. Create a new index.html file.

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

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

    1. $ docker port mysite
    2. 80/tcp -> 0.0.0.0:49166
    3. 443/tcp -> 0.0.0.0:49165
  7. Open the site in a browser:

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

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

  10. Stop and then remove your running mysite container.

    1. $ docker stop mysite
    2. $ 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:

  1. Open a terminal on your local machine.

  2. Stop the boot2docker application.

    1. $ boot2docker stop
  3. Run the upgrade command.

    1. $ boot2docker upgrade

Use the installer

To upgrade any version of Boot2Docker, do this:

  1. Open a terminal on your local machine.

  2. Stop the boot2docker application.

    1. $ boot2docker stop
  3. Go to the boot2docker/osx-installerrelease page.

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

  5. 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

Install Docker on Mac OS X(转)的更多相关文章

  1. Install wget in Mac OS X Without Homebrew or MacPorts

    May 22, 2012 - 31 Comments The command line tool wget lets you retrieve a group of files from FTP an ...

  2. Install MySQL on Mac OS X——MAC安装MySQL

    很多关于如何安装MySQL的教程已经过时了,或者比必须的步骤复杂得多.这篇教程将展示如何安装MySQL,启动MySQL,以root用户进入MySQL,以及创建删除退出数据库. Step 1: 下载My ...

  3. Mac OS X 软件推荐

    ​1. 前言 每个操作系统都有自己的一套软件系统,但是不同的用户却会有不同的需求,系统虽会为用户提供一些基础软件,不过为了能无碍的进入自己的学习和工作状态,总有一些软件是必须安装的,同时这些软件也可以 ...

  4. Mac OS X 下安装使用 Docker

    它依赖于 LXC(Linux Container),能从网络上获得配置好的 Linux 镜像,非常容易在隔离的系统中运行自己的应用.也因为它的底层核心是个 LXC,所以在 Mac OS X 下需要在 ...

  5. 在 Mac OS X 上安装 Docker(转)

    http://www.oschina.net/translate/installing-docker-on-mac-os-x?print 在 Mac OS X 上安装 Docker 注意:Docker ...

  6. docker on Mac

    贡献一篇: 云主机可以选择操作系统镜像快速创建主机,这比虚拟机更便捷了,我们本地也可以这么做了,因为有了 Docker 这个东西.它依赖于 LXC(Linux Container),能从网络上获得配置 ...

  7. 在 Mac OS 上创建并运行 ASP.NET Core 1.0 网站

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  8. How To Fix – Mcrypt PHP extension required in Laravel on Mac OS X (No MAMP)

    Laravel PHP web framework requires certain libraries to function properly. One of these libraries is ...

  9. [转]Debugging the Mac OS X kernel with VMware and GDB

    Source: http://ho.ax/posts/2012/02/debugging-the-mac-os-x-kernel-with-vmware-and-gdb/ Source: http:/ ...

随机推荐

  1. 求教Sublime Text2 SublimeLinter插件安装问题

    昨天装了 SublimeLinter插件(代码语法检测),这个事插件的地址:https://github.com/Kronuz/SublimeLinter 按照作者的介绍配置了一下,发现语法检测不起作 ...

  2. 【转】ArrayList其实就那么一回事儿之源码浅析

    转自:http://www.cnblogs.com/dongying/p/4013271.html?utm_source=tuicool&utm_medium=referral ArrayLi ...

  3. CEF3开发者系列之类和接口

    CEF3基本的框架包含C/C++程 序接口,通过本地库的接口来实现,而这个库则会隔离宿主程序和 Chromium&Webkit的操作细节.它在浏览器控件和宿主程序之间提供紧密的整合,它支持用户 ...

  4. ABAP 单位转换函数

    CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'         EXPORTING           input                = wa_all-btg ...

  5. 20145213《Java程序设计》第三周学习总结

    20145213<Java程序设计>第三周学习总结 教材学习内容总结 正所谓距离产生美,上周我还倾心于Java表面的基础语法.其简单的流程结构,屈指可数的基本类型分类,早已烂熟于心的运算符 ...

  6. cocos2d-x 第一篇 环境搭建

    官网:http://www.cocos2d-x.org/ 下载一个稳定版的cocos2d-x (网址:http://download.cocos2d-x.org/ Github Repository ...

  7. Vi文档

    Vi简介 Vi是一种广泛存在于各种UNIX和Linux系统中的文本编辑程序. Vi不是排版程序,只是一个纯粹的文本编辑程序. Vi是全屏幕文本编辑器,它没有菜单,只有命令. Vi不是基于窗口的,所以, ...

  8. loadrunner备忘

    1.超时设置 2. 可能是操作系统的环境不适合或者浏览器的版本有出入,具体的loadrunner版本支持的IE版本版本如下所示,请仔细核对是否正确.LR版本和IE版本兼容性问题,这个问题是我们安装环境 ...

  9. SQLServer基本操作

    SQL 全名是结构化查询语言(Structured Query Language),是关系数据库管理系统的标准语言 1.分离数据库:将当前数据库文件和数据库引擎的关系断开,没有任何关系了,这样就可以随 ...

  10. Android Service 与 IntentService

    Service 中的耗时操作必须 在 Thread中进行: IntentService 则直接在 onHandleIntent()方法中进行