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