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