github.com/ncdc/docker@v0.10.1-0.20160129113957-6c6729ef5b74/docs/installation/mac.md (about) 1 <!--[metadata]> 2 +++ 3 title = "Installation on Mac OS X" 4 description = "Instructions for installing Docker on OS X using boot2docker." 5 keywords = ["Docker, Docker documentation, requirements, boot2docker, VirtualBox, SSH, Linux, OSX, OS X, Mac"] 6 [menu.main] 7 parent = "engine_install" 8 weight="-90" 9 +++ 10 <![end-metadata]--> 11 12 # Mac OS X 13 14 > **Note**: This release of Docker deprecates the Boot2Docker command line in 15 > favor of Docker Machine. Use the Docker Toolbox to install Docker Machine as 16 > well as the other Docker tools. 17 18 You install Docker using Docker Toolbox. Docker Toolbox includes the following Docker tools: 19 20 * Docker Machine for running the `docker-machine` binary 21 * Docker Engine for running the `docker` binary 22 * Docker Compose for running the `docker-compose` binary 23 * Kitematic, the Docker GUI 24 * a shell preconfigured for a Docker command-line environment 25 * Oracle VM VirtualBox 26 27 Because the Docker daemon uses Linux-specific kernel features, you can't run 28 Docker natively in OS X. Instead, you must use `docker-machine` to create and 29 attach to a virtual machine (VM). This machine is a Linux VM that hosts Docker 30 for you on your Mac. 31 32 **Requirements** 33 34 Your Mac must be running OS X 10.8 "Mountain Lion" or newer to install the 35 Docker Toolbox. 36 37 ### Learn the key concepts before installing 38 39 In a Docker installation on Linux, your physical machine is both the localhost 40 and the Docker host. In networking, localhost means your computer. The Docker 41 host is the computer on which the containers run. 42 43 On a typical Linux installation, the Docker client, the Docker daemon, and any 44 containers run directly on your localhost. This means you can address ports on a 45 Docker container using standard localhost addressing such as `localhost:8000` or 46 `0.0.0.0:8376`. 47 48  49 50 In an OS X installation, the `docker` daemon is running inside a Linux VM called 51 `default`. The `default` is a lightweight Linux VM made specifically to run 52 the Docker daemon on Mac OS X. The VM runs completely from RAM, is a small ~24MB 53 download, and boots in approximately 5s. 54 55  56 57 In OS X, the Docker host address is the address of the Linux VM. When you start 58 the VM with `docker-machine` it is assigned an IP address. When you start a 59 container, the ports on a container map to ports on the VM. To see this in 60 practice, work through the exercises on this page. 61 62 63 ### Installation 64 65 If you have VirtualBox running, you must shut it down before running the 66 installer. 67 68 1. Go to the [Docker Toolbox](https://www.docker.com/toolbox) page. 69 70 2. Click the installer link to download. 71 72 3. Install Docker Toolbox by double-clicking the package or by right-clicking 73 and choosing "Open" from the pop-up menu. 74 75 The installer launches the "Install Docker Toolbox" dialog. 76 77  78 79 4. Press "Continue" to install the toolbox. 80 81 The installer presents you with options to customize the standard 82 installation. 83 84  85 86 By default, the standard Docker Toolbox installation: 87 88 * installs binaries for the Docker tools in `/usr/local/bin` 89 * makes these binaries available to all users 90 * installs VirtualBox; or updates any existing installation 91 92 Change these defaults by pressing "Customize" or "Change 93 Install Location." 94 95 5. Press "Install" to perform the standard installation. 96 97 The system prompts you for your password. 98 99  100 101 6. Provide your password to continue with the installation. 102 103 When it completes, the installer provides you with some information you can 104 use to complete some common tasks. 105 106  107 108 7. Press "Close" to exit. 109 110 111 ## Running a Docker Container 112 113 To run a Docker container, you: 114 115 * create a new (or start an existing) virtual machine that runs Docker. 116 * switch your environment to your new VM 117 * use the `docker` client to create, load, and manage containers 118 119 Once you create a machine, you can reuse it as often as you like. Like any 120 VirtualBox VM, it maintains its configuration between uses. 121 122 There are two ways to use the installed tools, from the Docker Quickstart Terminal or 123 [from your shell](#from-your-shell). 124 125 ### From the Docker Quickstart Terminal 126 127 1. Open the "Applications" folder or the "Launchpad". 128 129 2. Find the Docker Quickstart Terminal and double-click to launch it. 130 131 The application: 132 133 * opens a terminal window 134 * creates a `default` VM if it doesn't exists, and starts the VM after 135 * points the terminal environment to this VM 136 137 Once the launch completes, the Docker Quickstart Terminal reports: 138 139  140 141 Now, you can run `docker` commands. 142 143 3. Verify your setup succeeded by running the `hello-world` container. 144 145 $ docker run hello-world 146 Unable to find image 'hello-world:latest' locally 147 511136ea3c5a: Pull complete 148 31cbccb51277: Pull complete 149 e45a5af57b00: Pull complete 150 hello-world:latest: The image you are pulling has been verified. 151 Important: image verification is a tech preview feature and should not be 152 relied on to provide security. 153 Status: Downloaded newer image for hello-world:latest 154 Hello from Docker. 155 This message shows that your installation appears to be working correctly. 156 157 To generate this message, Docker took the following steps: 158 1. The Docker client contacted the Docker daemon. 159 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 160 (Assuming it was not already locally available.) 161 3. The Docker daemon created a new container from that image which runs the 162 executable that produces the output you are currently reading. 163 4. The Docker daemon streamed that output to the Docker client, which sent it 164 to your terminal. 165 166 To try something more ambitious, you can run an Ubuntu container with: 167 $ docker run -it ubuntu bash 168 169 For more examples and ideas, visit: 170 http://docs.docker.com/userguide/ 171 172 173 A more typical way to interact with the Docker tools is from your regular shell command line. 174 175 ### From your shell 176 177 This section assumes you are running a Bash shell. You may be running a 178 different shell such as C Shell but the commands are the same. 179 180 1. Create a new Docker VM. 181 182 $ docker-machine create --driver virtualbox default 183 Creating VirtualBox VM... 184 Creating SSH key... 185 Starting VirtualBox VM... 186 Starting VM... 187 To see how to connect Docker to this machine, run: docker-machine env default 188 189 This creates a new `default` VM in VirtualBox. 190 191 The command also creates a machine configuration in the 192 `~/.docker/machine/machines/default` directory. You only need to run the 193 `create` command once. Then, you can use `docker-machine` to start, stop, 194 query, and otherwise manage the VM from the command line. 195 196 2. List your available machines. 197 198 $ docker-machine ls 199 NAME ACTIVE DRIVER STATE URL SWARM 200 default * virtualbox Running tcp://192.168.99.101:2376 201 202 If you have previously installed the deprecated Boot2Docker application or 203 run the Docker Quickstart Terminal, you may have a `dev` VM as well. When you 204 created `default` VM, the `docker-machine` command provided instructions 205 for learning how to connect the VM. 206 207 3. Get the environment commands for your new VM. 208 209 $ docker-machine env default 210 export DOCKER_TLS_VERIFY="1" 211 export DOCKER_HOST="tcp://192.168.99.101:2376" 212 export DOCKER_CERT_PATH="/Users/mary/.docker/machine/machines/default" 213 export DOCKER_MACHINE_NAME="default" 214 # Run this command to configure your shell: 215 # eval "$(docker-machine env default)" 216 217 4. Connect your shell to the `default` machine. 218 219 $ eval "$(docker-machine env default)" 220 221 5. Run the `hello-world` container to verify your setup. 222 223 $ docker run hello-world 224 225 226 ## Learn about your Toolbox installation 227 228 Toolbox installs the Docker Engine binary, the Docker binary on your system. When you 229 use the Docker Quickstart Terminal or create a `default` VM manually, Docker 230 Machine updates the `~/.docker/machine/machines/default` folder to your 231 system. This folder contains the configuration for the VM. 232 233 You can create multiple VMs on your system with Docker Machine. Therefore, you 234 may end up with multiple VM folders if you have more than one VM. To remove a 235 VM, use the `docker-machine rm <machine-name>` command. 236 237 ## Migrate from Boot2Docker 238 239 If you were using Boot2Docker previously, you have a pre-existing Docker 240 `boot2docker-vm` VM on your local system. To allow Docker Machine to manage 241 this older VM, you can migrate it. 242 243 1. Open a terminal or the Docker CLI on your system. 244 245 2. Type the following command. 246 247 $ docker-machine create -d virtualbox --virtualbox-import-boot2docker-vm boot2docker-vm docker-vm 248 249 3. Use the `docker-machine` command to interact with the migrated VM. 250 251 The `docker-machine` subcommands are slightly different than the `boot2docker` 252 subcommands. The table below lists the equivalent `docker-machine` subcommand 253 and what it does: 254 255 | `boot2docker` | `docker-machine` | `docker-machine` description | 256 |----------------|------------------|----------------------------------------------------------| 257 | init | create | Creates a new docker host. | 258 | up | start | Starts a stopped machine. | 259 | ssh | ssh | Runs a command or interactive ssh session on the machine.| 260 | save | - | Not applicable. | 261 | down | stop | Stops a running machine. | 262 | poweroff | stop | Stops a running machine. | 263 | reset | restart | Restarts a running machine. | 264 | config | inspect | Prints machine configuration details. | 265 | status | ls | Lists all machines and their status. | 266 | info | inspect | Displays a machine's details. | 267 | ip | ip | Displays the machine's ip address. | 268 | shellinit | env | Displays shell commands needed to configure your shell to interact with a machine | 269 | delete | rm | Removes a machine. | 270 | download | - | Not applicable. | 271 | upgrade | upgrade | Upgrades a machine's Docker client to the latest stable release. | 272 273 274 ## Example of Docker on Mac OS X 275 276 Work through this section to try some practical container tasks on a VM. At this 277 point, you should have a VM running and be connected to it through your shell. 278 To verify this, run the following commands: 279 280 $ docker-machine ls 281 NAME ACTIVE DRIVER STATE URL SWARM 282 default * virtualbox Running tcp://192.168.99.100:2376 283 284 The `ACTIVE` machine, in this case `default`, is the one your environment is pointing to. 285 286 ### Access container ports 287 288 1. Start an NGINX container on the DOCKER_HOST. 289 290 $ docker run -d -P --name web nginx 291 292 Normally, the `docker run` commands starts a container, runs it, and then 293 exits. The `-d` flag keeps the container running in the background 294 after the `docker run` command completes. The `-P` flag publishes exposed ports from the 295 container to your local host; this lets you access them from your Mac. 296 297 2. Display your running container with `docker ps` command 298 299 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 300 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 301 302 At this point, you can see `nginx` is running as a daemon. 303 304 3. View just the container's ports. 305 306 $ docker port web 307 443/tcp -> 0.0.0.0:49156 308 80/tcp -> 0.0.0.0:49157 309 310 This tells you that the `web` container's port `80` is mapped to port 311 `49157` on your Docker host. 312 313 4. Enter the `http://localhost:49157` address (`localhost` is `0.0.0.0`) in your browser: 314 315  316 317 This didn't work. The reason it doesn't work is your `DOCKER_HOST` address is 318 not the localhost address (0.0.0.0) but is instead the address of the 319 your Docker VM. 320 321 5. Get the address of the `default` VM. 322 323 $ docker-machine ip default 324 192.168.59.103 325 326 6. Enter the `http://192.168.59.103:49157` address in your browser: 327 328  329 330 Success! 331 332 7. To stop and then remove your running `nginx` container, do the following: 333 334 $ docker stop web 335 $ docker rm web 336 337 ### Mount a volume on the container 338 339 When you start a container it automatically shares your `/Users/username` directory 340 with the VM. You can use this share point to mount directories onto your container. 341 The next exercise demonstrates how to do this. 342 343 1. Change to your user `$HOME` directory. 344 345 $ cd $HOME 346 347 2. Make a new `site` directory. 348 349 $ mkdir site 350 351 3. Change into the `site` directory. 352 353 $ cd site 354 355 4. Create a new `index.html` file. 356 357 $ echo "my new site" > index.html 358 359 5. Start a new `nginx` container and replace the `html` folder with your `site` directory. 360 361 $ docker run -d -P -v $HOME/site:/usr/share/nginx/html \ 362 --name mysite nginx 363 364 6. Get the `mysite` container's port. 365 366 $ docker port mysite 367 80/tcp -> 0.0.0.0:49166 368 443/tcp -> 0.0.0.0:49165 369 370 7. Open the site in a browser: 371 372  373 374 8. Try adding a page to your `$HOME/site` in real time. 375 376 $ echo "This is cool" > cool.html 377 378 9. Open the new page in the browser. 379 380  381 382 10. Stop and then remove your running `mysite` container. 383 384 $ docker stop mysite 385 $ docker rm mysite 386 387 388 ## Upgrade Docker Toolbox 389 390 To upgrade Docker Toolbox, download an re-run [the Docker Toolbox 391 installer](https://docker.com/toolbox/). 392 393 394 ## Uninstall Docker Toolbox 395 396 To uninstall, do the following: 397 398 1. List your machines. 399 400 $ docker-machine ls 401 NAME ACTIVE DRIVER STATE URL SWARM 402 dev * virtualbox Running tcp://192.168.99.100:2376 403 my-docker-machine virtualbox Stopped 404 default virtualbox Stopped 405 406 2. Remove each machine. 407 408 $ docker-machine rm dev 409 Successfully removed dev 410 411 Removing a machine deletes its VM from VirtualBox and from the 412 `~/.docker/machine/machines` directory. 413 414 3. Remove the Docker Quickstart Terminal and Kitematic from your "Applications" folder. 415 416 4. Remove the `docker`, `docker-compose`, and `docker-machine` commands from the `/usr/local/bin` folder. 417 418 $ rm /usr/local/bin/docker 419 420 5. Delete the `~/.docker` folder from your system. 421 422 423 ## Learning more 424 425 Use `docker-machine help` to list the full command line reference for Docker Machine. For more 426 information about using SSH or SCP to access a VM, see [the Docker Machine 427 documentation](https://docs.docker.com/machine/). 428 429 You can continue with the [Docker User Guide](../userguide/index.md). If you are 430 interested in using the Kitematic GUI, see the [Kitematic user 431 guide](https://docs.docker.com/kitematic/userguide/).