github.com/jogo/docker@v1.7.0-rc1/docs/sources/installation/mac.md (about)

     1  page_title: Installation on Mac OS X
     2  page_description: Instructions for installing Docker on OS X using boot2docker.
     3  page_keywords: Docker, Docker documentation, requirements, boot2docker, VirtualBox, SSH, Linux, OSX, OS X, Mac
     4  
     5  # Mac OS X
     6  
     7  You can install Docker using Boot2Docker to run `docker` commands at your command-line.
     8  Choose this installation if you are familiar with the command-line or plan to
     9  contribute to the Docker project on GitHub.
    10  
    11  [<img src="/installation/images/kitematic.png" alt="Download Kitematic"
    12  style="float:right;">](/kitematic/)
    13  
    14  Alternatively, you may want to try <a id="inlinelink" href="https://kitematic.com/"
    15  target="_blank">Kitematic</a>, an application that lets you set up Docker and
    16  run containers using a graphical user interface (GUI).
    17  
    18  ## Command-line Docker with Boot2Docker
    19  
    20  Because the Docker daemon uses Linux-specific kernel features, you can't run
    21  Docker natively in OS X. Instead, you must install the Boot2Docker application.
    22  The application includes a VirtualBox Virtual Machine (VM), Docker itself, and the
    23  Boot2Docker management tool.
    24  
    25  The Boot2Docker management tool is a lightweight Linux virtual machine made
    26  specifically to run the Docker daemon on Mac OS X. The VirtualBox VM runs
    27  completely from RAM, is a small ~24MB download, and boots in approximately 5s.
    28  
    29  **Requirements**
    30  
    31  Your Mac must be running OS X 10.6 "Snow Leopard" or newer to run Boot2Docker.
    32  
    33  ### Learn the key concepts before installing
    34  
    35  In a Docker installation on Linux, your machine is both the localhost and the
    36  Docker host. In networking, localhost means your computer. The Docker host is
    37  the machine on which the containers run.
    38  
    39  On a typical Linux installation, the Docker client, the Docker daemon, and any
    40  containers run directly on your localhost. This means you can address ports on a
    41  Docker container using standard localhost addressing such as `localhost:8000` or
    42  `0.0.0.0:8376`.
    43  
    44  ![Linux Architecture Diagram](/installation/images/linux_docker_host.svg)
    45  
    46  In an OS X installation, the `docker` daemon is running inside a Linux virtual
    47  machine provided by Boot2Docker.
    48  
    49  ![OSX Architecture Diagram](/installation/images/mac_docker_host.svg)
    50  
    51  In OS X, the Docker host address is the address of the Linux VM.
    52  When you start the `boot2docker` process, the VM is assigned an IP address. Under
    53  `boot2docker` ports on a container map to ports on the VM. To see this in
    54  practice, work through the exercises on this page.
    55  
    56  
    57  ### Installation
    58  
    59  1. Go to the [boot2docker/osx-installer ](
    60     https://github.com/boot2docker/osx-installer/releases/latest) release page.
    61  
    62  4. Download Boot2Docker by clicking `Boot2Docker-x.x.x.pkg` in the "Downloads"
    63     section.
    64  
    65  3. Install Boot2Docker by double-clicking the package.
    66  
    67      The installer places Boot2Docker in your "Applications" folder.
    68  
    69  The installation places the `docker` and `boot2docker` binaries in your
    70  `/usr/local/bin` directory.
    71  
    72  
    73  ## Start the Boot2Docker Application
    74  
    75  To run a Docker container, you first start the `boot2docker` VM and then issue
    76  `docker` commands to create, load, and manage containers. You can launch
    77  `boot2docker` from your Applications folder or from the command line.
    78  
    79  > **NOTE**: Boot2Docker is designed as a development tool. You should not use
    80  >  it in production environments.
    81  
    82  ### From the Applications folder
    83  
    84  When you launch the "Boot2Docker" application from your "Applications" folder, the
    85  application:
    86  
    87  * opens a terminal window
    88  
    89  * creates a $HOME/.boot2docker directory
    90  
    91  * creates a VirtualBox ISO and certs
    92  
    93  * starts a VirtualBox VM running the `docker` daemon
    94  
    95  Once the launch completes, you can run `docker` commands. A good way to verify
    96  your setup succeeded is to run the `hello-world` container.
    97  
    98      $ docker run hello-world
    99      Unable to find image 'hello-world:latest' locally
   100      511136ea3c5a: Pull complete
   101      31cbccb51277: Pull complete
   102      e45a5af57b00: Pull complete
   103      hello-world:latest: The image you are pulling has been verified.
   104      Important: image verification is a tech preview feature and should not be
   105      relied on to provide security.
   106      Status: Downloaded newer image for hello-world:latest
   107      Hello from Docker.
   108      This message shows that your installation appears to be working correctly.
   109  
   110      To generate this message, Docker took the following steps:
   111      1. The Docker client contacted the Docker daemon.
   112      2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
   113         (Assuming it was not already locally available.)
   114      3. The Docker daemon created a new container from that image which runs the
   115         executable that produces the output you are currently reading.
   116      4. The Docker daemon streamed that output to the Docker client, which sent it
   117         to your terminal.
   118  
   119      To try something more ambitious, you can run an Ubuntu container with:
   120      $ docker run -it ubuntu bash
   121  
   122      For more examples and ideas, visit:
   123      http://docs.docker.com/userguide/
   124  
   125  
   126  A more typical way to start and stop `boot2docker` is using the command line.
   127  
   128  ### From your command line
   129  
   130  Initialize and run `boot2docker` from the command line, do the following:
   131  
   132  1. Create a new Boot2Docker VM.
   133  
   134          $ boot2docker init
   135  
   136      This creates a new virtual machine. You only need to run this command once.
   137  
   138  2. Start the `boot2docker` VM.
   139  
   140          $ boot2docker start
   141  
   142  3. Display the environment variables for the Docker client.
   143  
   144          $ boot2docker shellinit
   145          Writing /Users/mary/.boot2docker/certs/boot2docker-vm/ca.pem
   146          Writing /Users/mary/.boot2docker/certs/boot2docker-vm/cert.pem
   147          Writing /Users/mary/.boot2docker/certs/boot2docker-vm/key.pem
   148              export DOCKER_HOST=tcp://192.168.59.103:2376
   149              export DOCKER_CERT_PATH=/Users/mary/.boot2docker/certs/boot2docker-vm
   150              export DOCKER_TLS_VERIFY=1
   151  
   152      The specific paths and address on your machine will be different.
   153  
   154  4. To set the environment variables in your shell do the following:
   155  
   156          $ eval "$(boot2docker shellinit)"
   157  
   158      You can also set them manually by using the `export` commands `boot2docker`
   159      returns.
   160  
   161  5. Run the `hello-world` container to verify your setup.
   162  
   163          $ docker run hello-world
   164  
   165  
   166  ## Basic Boot2Docker exercises
   167  
   168  At this point, you should have `boot2docker` running and the `docker` client
   169  environment initialized. To verify this, run the following commands:
   170  
   171      $ boot2docker status
   172      $ docker version
   173  
   174  Work through this section to try some practical container tasks using `boot2docker` VM.
   175  
   176  ### Access container ports
   177  
   178  1. Start an NGINX container on the DOCKER_HOST.
   179  
   180          $ docker run -d -P --name web nginx
   181  
   182      Normally, the `docker run` commands starts a container, runs it, and then
   183      exits. The `-d` flag keeps the container running in the background
   184      after the `docker run` command completes. The `-P` flag publishes exposed ports from the
   185      container to your local host; this lets you access them from your Mac.
   186  
   187  2. Display your running container with `docker ps` command
   188  
   189          CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                                           NAMES
   190          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  
   191  
   192      At this point, you can see `nginx` is running as a daemon.
   193  
   194  3. View just the container's ports.
   195  
   196          $ docker port web
   197          443/tcp -> 0.0.0.0:49156
   198          80/tcp -> 0.0.0.0:49157
   199  
   200      This tells you that the `web` container's port `80` is mapped to port
   201      `49157` on your Docker host.
   202  
   203  4. Enter the `http://localhost:49157` address (`localhost` is `0.0.0.0`) in your browser:
   204  
   205      ![Bad Address](/installation/images/bad_host.png)
   206  
   207      This didn't work. The reason it doesn't work is your `DOCKER_HOST` address is
   208      not the localhost address (0.0.0.0) but is instead the address of the
   209      `boot2docker` VM.
   210  
   211  5. Get the address of the `boot2docker` VM.
   212  
   213          $ boot2docker ip
   214          192.168.59.103
   215  
   216  6. Enter the `http://192.168.59.103:49157` address in your browser:
   217  
   218      ![Correct Addressing](/installation/images/good_host.png)
   219  
   220      Success!
   221  
   222  7. To stop and then remove your running `nginx` container, do the following:
   223  
   224          $ docker stop web
   225          $ docker rm web
   226  
   227  ### Mount a volume on the container
   228  
   229  When you start `boot2docker`, it automatically shares your `/Users` directory
   230  with the VM. You can use this share point to mount directories onto your container.
   231  The next exercise demonstrates how to do this.
   232  
   233  1. Change to your user `$HOME` directory.
   234  
   235          $ cd $HOME
   236  
   237  2. Make a new `site` directory.
   238  
   239          $ mkdir site
   240  
   241  3. Change into the `site` directory.
   242  
   243          $ cd site
   244  
   245  4. Create a new `index.html` file.
   246  
   247          $ echo "my new site" > index.html
   248  
   249  5. Start a new `nginx` container and replace the `html` folder with your `site` directory.
   250  
   251          $ docker run -d -P -v $HOME/site:/usr/share/nginx/html --name mysite nginx
   252  
   253  6. Get the `mysite` container's port.
   254  
   255          $ docker port mysite
   256          80/tcp -> 0.0.0.0:49166
   257          443/tcp -> 0.0.0.0:49165
   258  
   259  7. Open the site in a browser:
   260  
   261      ![My site page](/installation/images/newsite_view.png)
   262  
   263  8. Try adding a page to your `$HOME/site` in real time.
   264  
   265          $ echo "This is cool" > cool.html
   266  
   267  9. Open the new page in the browser.
   268  
   269      ![Cool page](/installation/images/cool_view.png)
   270  
   271  9. Stop and then remove your running `mysite` container.
   272  
   273          $ docker stop mysite
   274          $ docker rm mysite
   275  
   276  ## Upgrade Boot2Docker
   277  
   278  If you running Boot2Docker 1.4.1 or greater, you can upgrade Boot2Docker from
   279  the command line. If you are running an older version, you should use the
   280  package provided by the `boot2docker` repository.
   281  
   282  ### From the command line
   283  
   284  To upgrade from 1.4.1 or greater, you can do this:
   285  
   286  1. Open a terminal on your local machine.
   287  
   288  2. Stop the `boot2docker` application.
   289  
   290          $ boot2docker stop
   291  
   292  3. Run the upgrade command.
   293  
   294          $ boot2docker upgrade
   295  
   296  
   297  ### Use the installer
   298  
   299  To upgrade any version of Boot2Docker, do this:
   300  
   301  1. Open a terminal on your local machine.
   302  
   303  2. Stop the `boot2docker` application.
   304  
   305          $ boot2docker stop
   306  
   307  3. Go to the [boot2docker/osx-installer ](
   308     https://github.com/boot2docker/osx-installer/releases/latest) release page.
   309  
   310  4. Download Boot2Docker by clicking `Boot2Docker-x.x.x.pkg` in the "Downloads"
   311     section.
   312  
   313  2. Install Boot2Docker by double-clicking the package.
   314  
   315      The installer places Boot2Docker in your "Applications" folder.
   316  
   317  
   318  ## Uninstallation 
   319  
   320  1. Go to the [boot2docker/osx-installer ](
   321     https://github.com/boot2docker/osx-installer/releases/latest) release page. 
   322  
   323  2. Download the source code by clicking `Source code (zip)` or
   324     `Source code (tar.gz)` in the "Downloads" section.
   325  
   326  3. Extract the source code.
   327  
   328  4. Open a terminal on your local machine.
   329  
   330  5. Change to the directory where you extracted the source code:
   331  
   332          $ cd <path to extracted source code>
   333  
   334  6. Make sure the uninstall.sh script is executable:
   335  
   336          $ chmod +x uninstall.sh
   337  
   338  7. Run the uninstall.sh script:
   339  
   340          $ ./uninstall.sh
   341  
   342  
   343  ## Learning more and acknowledgement
   344  
   345  Use `boot2docker help` to list the full command line reference. For more
   346  information about using SSH or SCP to access the Boot2Docker VM, see the README
   347  at  [Boot2Docker repository](https://github.com/boot2docker/boot2docker).
   348  
   349  Thanks to Chris Jones whose [blog](http://goo.gl/Be6cCk)  inspired me to redo
   350  this page.
   351  
   352  Continue with the [Docker User Guide](/userguide/).