2015-06-07 23:07:20 -04:00
|
|
|
<!--[metadata]>
|
|
|
|
+++
|
|
|
|
title = "Installation on Mac OS X"
|
|
|
|
description = "Instructions for installing Docker on OS X using boot2docker."
|
|
|
|
keywords = ["Docker, Docker documentation, requirements, boot2docker, VirtualBox, SSH, Linux, OSX, OS X, Mac"]
|
|
|
|
[menu.main]
|
2016-01-23 23:36:40 -05:00
|
|
|
parent = "engine_install"
|
|
|
|
weight="-90"
|
2015-06-07 23:07:20 -04:00
|
|
|
+++
|
|
|
|
<![end-metadata]-->
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
# Mac OS X
|
2014-04-18 16:21:55 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
You install Docker using Docker Toolbox. Docker Toolbox includes the following Docker tools:
|
2015-05-19 01:10:06 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
* Docker Machine for running the `docker-machine` binary
|
|
|
|
* Docker Engine for running the `docker` binary
|
|
|
|
* Docker Compose for running the `docker-compose` binary
|
|
|
|
* Kitematic, the Docker GUI
|
|
|
|
* a shell preconfigured for a Docker command-line environment
|
2015-09-11 13:06:54 -04:00
|
|
|
* Oracle VM VirtualBox
|
2015-03-21 21:20:25 -04:00
|
|
|
|
2015-02-16 16:24:13 -05:00
|
|
|
Because the Docker daemon uses Linux-specific kernel features, you can't run
|
2015-07-12 10:09:14 -04:00
|
|
|
Docker natively in OS X. Instead, you must use `docker-machine` to create and
|
|
|
|
attach to a virtual machine (VM). This machine is a Linux VM that hosts Docker
|
|
|
|
for you on your Mac.
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-02-17 13:55:19 -05:00
|
|
|
**Requirements**
|
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
Your Mac must be running OS X 10.8 "Mountain Lion" or newer to install the
|
|
|
|
Docker Toolbox.
|
2014-05-05 08:52:12 -04:00
|
|
|
|
2015-03-21 21:20:25 -04:00
|
|
|
### Learn the key concepts before installing
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
In a Docker installation on Linux, your physical machine is both the localhost
|
|
|
|
and the Docker host. In networking, localhost means your computer. The Docker
|
|
|
|
host is the computer on which the containers run.
|
2015-02-17 13:55:19 -05:00
|
|
|
|
|
|
|
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
|
2015-02-17 18:59:29 -05:00
|
|
|
Docker container using standard localhost addressing such as `localhost:8000` or
|
2015-02-17 13:55:19 -05:00
|
|
|
`0.0.0.0:8376`.
|
2014-06-08 16:11:50 -04:00
|
|
|
|
2015-10-09 19:50:41 -04:00
|
|
|
![Linux Architecture Diagram](images/linux_docker_host.svg)
|
2014-05-05 08:52:12 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
In an OS X installation, the `docker` daemon is running inside a Linux VM called
|
2015-08-10 16:29:08 -04:00
|
|
|
`default`. The `default` is a lightweight Linux VM made specifically to run
|
2015-07-12 10:09:14 -04:00
|
|
|
the Docker daemon on Mac OS X. The VM runs completely from RAM, is a small ~24MB
|
|
|
|
download, and boots in approximately 5s.
|
2014-06-08 18:53:20 -04:00
|
|
|
|
2015-10-09 19:50:41 -04:00
|
|
|
![OSX Architecture Diagram](images/mac_docker_host.svg)
|
2014-06-08 18:53:20 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
In OS X, the Docker host address is the address of the Linux VM. When you start
|
|
|
|
the VM with `docker-machine` it is assigned an IP address. When you start a
|
|
|
|
container, the ports on a container map to ports on the VM. To see this in
|
2015-02-17 13:55:19 -05:00
|
|
|
practice, work through the exercises on this page.
|
2014-06-08 18:53:20 -04:00
|
|
|
|
2014-05-05 08:52:12 -04:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
### Installation
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
If you have VirtualBox running, you must shut it down before running the
|
2015-09-11 13:06:54 -04:00
|
|
|
installer.
|
2014-07-21 16:53:58 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
1. Go to the [Docker Toolbox](https://www.docker.com/toolbox) page.
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2016-02-27 21:30:32 -05:00
|
|
|
2. Click the Download link.
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
3. Install Docker Toolbox by double-clicking the package or by right-clicking
|
|
|
|
and choosing "Open" from the pop-up menu.
|
2014-12-29 03:19:42 -05:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
The installer launches the "Install Docker Toolbox" dialog.
|
2015-09-11 13:06:54 -04:00
|
|
|
|
2015-10-09 19:50:41 -04:00
|
|
|
![Install Docker Toolbox](images/mac-welcome-page.png)
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
4. Press "Continue" to install the toolbox.
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
The installer presents you with options to customize the standard
|
2015-09-11 13:06:54 -04:00
|
|
|
installation.
|
|
|
|
|
2015-10-09 19:50:41 -04:00
|
|
|
![Standard install](images/mac-page-two.png)
|
2015-09-11 13:06:54 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
By default, the standard Docker Toolbox installation:
|
2015-09-11 13:06:54 -04:00
|
|
|
|
|
|
|
* installs binaries for the Docker tools in `/usr/local/bin`
|
|
|
|
* makes these binaries available to all users
|
2015-08-22 11:00:48 -04:00
|
|
|
* installs VirtualBox; or updates any existing installation
|
2015-09-11 13:06:54 -04:00
|
|
|
|
2016-02-27 21:30:32 -05:00
|
|
|
To change these defaults, press "Customize" or "Change
|
2015-09-11 13:06:54 -04:00
|
|
|
Install Location."
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
5. Press "Install" to perform the standard installation.
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
The system prompts you for your password.
|
2015-09-11 13:06:54 -04:00
|
|
|
|
2015-10-09 19:50:41 -04:00
|
|
|
![Password prompt](images/mac-password-prompt.png)
|
2015-09-11 13:06:54 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
6. Provide your password to continue with the installation.
|
2014-05-28 00:42:19 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
When it completes, the installer provides you with some information you can
|
|
|
|
use to complete some common tasks.
|
2015-09-11 13:06:54 -04:00
|
|
|
|
2015-10-09 19:50:41 -04:00
|
|
|
![All finished](images/mac-page-finished.png)
|
2015-09-11 13:06:54 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
7. Press "Close" to exit.
|
2015-04-29 15:51:57 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
## Running a Docker Container
|
2015-04-29 15:51:57 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
To run a Docker container, you:
|
2014-05-28 00:42:19 -04:00
|
|
|
|
2016-02-27 21:30:32 -05:00
|
|
|
* Create a new (or start an existing) virtual machine
|
|
|
|
* Switch your environment to your new VM
|
|
|
|
* Use the `docker` client to create, load, and manage containers
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2016-02-27 21:30:32 -05:00
|
|
|
You can reuse this virtual machine as often as you like. Like any
|
2015-07-12 10:09:14 -04:00
|
|
|
VirtualBox VM, it maintains its configuration between uses.
|
2014-05-28 00:42:19 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
There are two ways to use the installed tools, from the Docker Quickstart Terminal or
|
|
|
|
[from your shell](#from-your-shell).
|
2014-05-21 17:05:19 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
### From the Docker Quickstart Terminal
|
2014-06-13 18:38:45 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
1. Open the "Applications" folder or the "Launchpad".
|
2014-05-21 17:05:19 -04:00
|
|
|
|
2015-08-22 11:00:48 -04:00
|
|
|
2. Find the Docker Quickstart Terminal and double-click to launch it.
|
2014-05-28 00:42:19 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
The application:
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2016-02-27 21:30:32 -05:00
|
|
|
* Opens a terminal window
|
|
|
|
* Creates a `default` VM if it doesn't exists, and starts the VM after
|
|
|
|
* Points the terminal environment to this VM
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
Once the launch completes, the Docker Quickstart Terminal reports:
|
2015-09-11 13:06:54 -04:00
|
|
|
|
2015-10-09 19:50:41 -04:00
|
|
|
![All finished](images/mac-success.png)
|
2015-09-11 13:06:54 -04:00
|
|
|
|
|
|
|
Now, you can run `docker` commands.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
3. Verify your setup succeeded by running the `hello-world` container.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
$ docker run hello-world
|
|
|
|
Unable to find image 'hello-world:latest' locally
|
|
|
|
511136ea3c5a: Pull complete
|
|
|
|
31cbccb51277: Pull complete
|
|
|
|
e45a5af57b00: Pull complete
|
|
|
|
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.
|
|
|
|
Status: Downloaded newer image for hello-world:latest
|
|
|
|
Hello from Docker.
|
|
|
|
This message shows that your installation appears to be working correctly.
|
|
|
|
|
|
|
|
To generate this message, Docker took the following steps:
|
|
|
|
1. The Docker client contacted the Docker daemon.
|
|
|
|
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
|
|
|
|
(Assuming it was not already locally available.)
|
|
|
|
3. The Docker daemon created a new container from that image which runs the
|
|
|
|
executable that produces the output you are currently reading.
|
|
|
|
4. The Docker daemon streamed that output to the Docker client, which sent it
|
|
|
|
to your terminal.
|
|
|
|
|
|
|
|
To try something more ambitious, you can run an Ubuntu container with:
|
|
|
|
$ docker run -it ubuntu bash
|
|
|
|
|
|
|
|
For more examples and ideas, visit:
|
|
|
|
http://docs.docker.com/userguide/
|
|
|
|
|
|
|
|
|
|
|
|
A more typical way to interact with the Docker tools is from your regular shell command line.
|
|
|
|
|
|
|
|
### From your shell
|
|
|
|
|
|
|
|
This section assumes you are running a Bash shell. You may be running a
|
|
|
|
different shell such as C Shell but the commands are the same.
|
|
|
|
|
|
|
|
1. Create a new Docker VM.
|
|
|
|
|
2015-08-10 16:29:08 -04:00
|
|
|
$ docker-machine create --driver virtualbox default
|
2015-07-12 10:09:14 -04:00
|
|
|
Creating VirtualBox VM...
|
|
|
|
Creating SSH key...
|
|
|
|
Starting VirtualBox VM...
|
|
|
|
Starting VM...
|
2015-08-10 16:29:08 -04:00
|
|
|
To see how to connect Docker to this machine, run: docker-machine env default
|
2015-07-12 10:09:14 -04:00
|
|
|
|
2015-08-22 11:00:48 -04:00
|
|
|
This creates a new `default` VM in VirtualBox.
|
2015-09-11 13:06:54 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
The command also creates a machine configuration in the
|
2015-08-10 16:29:08 -04:00
|
|
|
`~/.docker/machine/machines/default` directory. You only need to run the
|
2015-07-12 10:09:14 -04:00
|
|
|
`create` command once. Then, you can use `docker-machine` to start, stop,
|
|
|
|
query, and otherwise manage the VM from the command line.
|
2015-09-11 13:06:54 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
2. List your available machines.
|
|
|
|
|
|
|
|
$ docker-machine ls
|
|
|
|
NAME ACTIVE DRIVER STATE URL SWARM
|
2015-09-11 13:06:54 -04:00
|
|
|
default * virtualbox Running tcp://192.168.99.101:2376
|
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
If you have previously installed the deprecated Boot2Docker application or
|
|
|
|
run the Docker Quickstart Terminal, you may have a `dev` VM as well. When you
|
2015-08-22 11:00:48 -04:00
|
|
|
created `default` VM, the `docker-machine` command provided instructions
|
2015-07-12 10:09:14 -04:00
|
|
|
for learning how to connect the VM.
|
|
|
|
|
|
|
|
3. Get the environment commands for your new VM.
|
|
|
|
|
2015-08-10 16:29:08 -04:00
|
|
|
$ docker-machine env default
|
2015-07-12 10:09:14 -04:00
|
|
|
export DOCKER_TLS_VERIFY="1"
|
|
|
|
export DOCKER_HOST="tcp://192.168.99.101:2376"
|
2015-08-10 16:29:08 -04:00
|
|
|
export DOCKER_CERT_PATH="/Users/mary/.docker/machine/machines/default"
|
|
|
|
export DOCKER_MACHINE_NAME="default"
|
2015-09-11 13:06:54 -04:00
|
|
|
# Run this command to configure your shell:
|
2015-08-10 16:29:08 -04:00
|
|
|
# eval "$(docker-machine env default)"
|
2015-09-11 13:06:54 -04:00
|
|
|
|
2015-08-10 16:29:08 -04:00
|
|
|
4. Connect your shell to the `default` machine.
|
2015-07-12 10:09:14 -04:00
|
|
|
|
2015-08-10 16:29:08 -04:00
|
|
|
$ eval "$(docker-machine env default)"
|
2015-02-16 16:24:13 -05:00
|
|
|
|
|
|
|
5. Run the `hello-world` container to verify your setup.
|
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
$ docker run hello-world
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
## Learn about your Toolbox installation
|
|
|
|
|
|
|
|
Toolbox installs the Docker Engine binary, the Docker binary on your system. When you
|
2015-08-22 11:00:48 -04:00
|
|
|
use the Docker Quickstart Terminal or create a `default` VM manually, Docker
|
2015-08-10 16:29:08 -04:00
|
|
|
Machine updates the `~/.docker/machine/machines/default` folder to your
|
2015-07-12 10:09:14 -04:00
|
|
|
system. This folder contains the configuration for the VM.
|
|
|
|
|
2015-08-22 11:00:48 -04:00
|
|
|
You can create multiple VMs on your system with Docker Machine. Therefore, you
|
|
|
|
may end up with multiple VM folders if you have more than one VM. To remove a
|
|
|
|
VM, use the `docker-machine rm <machine-name>` command.
|
2015-08-10 16:29:08 -04:00
|
|
|
|
|
|
|
## Migrate from Boot2Docker
|
|
|
|
|
|
|
|
If you were using Boot2Docker previously, you have a pre-existing Docker
|
|
|
|
`boot2docker-vm` VM on your local system. To allow Docker Machine to manage
|
|
|
|
this older VM, you can migrate it.
|
|
|
|
|
|
|
|
1. Open a terminal or the Docker CLI on your system.
|
|
|
|
|
|
|
|
2. Type the following command.
|
|
|
|
|
|
|
|
$ docker-machine create -d virtualbox --virtualbox-import-boot2docker-vm boot2docker-vm docker-vm
|
2015-09-11 13:06:54 -04:00
|
|
|
|
|
|
|
3. Use the `docker-machine` command to interact with the migrated VM.
|
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
The `docker-machine` subcommands are slightly different than the `boot2docker`
|
|
|
|
subcommands. The table below lists the equivalent `docker-machine` subcommand
|
|
|
|
and what it does:
|
|
|
|
|
|
|
|
| `boot2docker` | `docker-machine` | `docker-machine` description |
|
|
|
|
|----------------|------------------|----------------------------------------------------------|
|
|
|
|
| init | create | Creates a new docker host. |
|
|
|
|
| up | start | Starts a stopped machine. |
|
|
|
|
| ssh | ssh | Runs a command or interactive ssh session on the machine.|
|
|
|
|
| save | - | Not applicable. |
|
|
|
|
| down | stop | Stops a running machine. |
|
|
|
|
| poweroff | stop | Stops a running machine. |
|
|
|
|
| reset | restart | Restarts a running machine. |
|
|
|
|
| config | inspect | Prints machine configuration details. |
|
|
|
|
| status | ls | Lists all machines and their status. |
|
|
|
|
| info | inspect | Displays a machine's details. |
|
|
|
|
| ip | ip | Displays the machine's ip address. |
|
|
|
|
| shellinit | env | Displays shell commands needed to configure your shell to interact with a machine |
|
|
|
|
| delete | rm | Removes a machine. |
|
|
|
|
| download | - | Not applicable. |
|
|
|
|
| upgrade | upgrade | Upgrades a machine's Docker client to the latest stable release. |
|
|
|
|
|
|
|
|
|
2016-02-27 21:30:32 -05:00
|
|
|
## Examples on Mac OS X
|
2015-07-12 10:09:14 -04:00
|
|
|
|
|
|
|
Work through this section to try some practical container tasks on a VM. At this
|
|
|
|
point, you should have a VM running and be connected to it through your shell.
|
|
|
|
To verify this, run the following commands:
|
|
|
|
|
|
|
|
$ docker-machine ls
|
|
|
|
NAME ACTIVE DRIVER STATE URL SWARM
|
2015-09-11 13:06:54 -04:00
|
|
|
default * virtualbox Running tcp://192.168.99.100:2376
|
2015-07-12 10:09:14 -04:00
|
|
|
|
2015-08-15 15:56:41 -04:00
|
|
|
The `ACTIVE` machine, in this case `default`, is the one your environment is pointing to.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
|
|
|
### Access container ports
|
|
|
|
|
|
|
|
1. Start an NGINX container on the DOCKER_HOST.
|
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
$ docker run -d -P --name web nginx
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
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.
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2015-02-16 16:24:13 -05:00
|
|
|
2. Display your running container with `docker ps` command
|
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
2015-09-11 13:06:54 -04:00
|
|
|
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
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
At this point, you can see `nginx` is running as a daemon.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
|
|
|
3. View just the container's ports.
|
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
$ docker port web
|
|
|
|
443/tcp -> 0.0.0.0:49156
|
|
|
|
80/tcp -> 0.0.0.0:49157
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
This tells you that the `web` container's port `80` is mapped to port
|
|
|
|
`49157` on your Docker host.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-02-28 13:53:48 -05:00
|
|
|
4. Enter the `http://localhost:49157` address (`localhost` is `0.0.0.0`) in your browser:
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-10-09 19:50:41 -04:00
|
|
|
![Bad Address](images/bad_host.png)
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
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
|
2015-07-12 10:09:14 -04:00
|
|
|
your Docker VM.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-08-15 15:56:41 -04:00
|
|
|
5. Get the address of the `default` VM.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-08-15 15:56:41 -04:00
|
|
|
$ docker-machine ip default
|
2015-04-29 15:51:57 -04:00
|
|
|
192.168.59.103
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2015-02-28 13:53:48 -05:00
|
|
|
6. Enter the `http://192.168.59.103:49157` address in your browser:
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-10-09 19:50:41 -04:00
|
|
|
![Correct Addressing](images/good_host.png)
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
Success!
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-02-17 19:10:32 -05:00
|
|
|
7. To stop and then remove your running `nginx` container, do the following:
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
$ docker stop web
|
|
|
|
$ docker rm web
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2015-02-16 16:24:13 -05:00
|
|
|
### Mount a volume on the container
|
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
When you start a container it automatically shares your `/Users/username` directory
|
2015-02-17 18:59:29 -05:00
|
|
|
with the VM. You can use this share point to mount directories onto your container.
|
2015-02-16 16:24:13 -05:00
|
|
|
The next exercise demonstrates how to do this.
|
|
|
|
|
2015-02-17 19:10:32 -05:00
|
|
|
1. Change to your user `$HOME` directory.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
$ cd $HOME
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2015-02-17 19:10:32 -05:00
|
|
|
2. Make a new `site` directory.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
$ mkdir site
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-02-17 19:10:32 -05:00
|
|
|
3. Change into the `site` directory.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
$ cd site
|
2015-02-16 16:24:13 -05:00
|
|
|
|
|
|
|
4. Create a new `index.html` file.
|
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
$ echo "my new site" > index.html
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2015-02-16 16:24:13 -05:00
|
|
|
5. Start a new `nginx` container and replace the `html` folder with your `site` directory.
|
|
|
|
|
2015-08-03 21:21:54 -04:00
|
|
|
$ docker run -d -P -v $HOME/site:/usr/share/nginx/html \
|
|
|
|
--name mysite nginx
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2016-02-27 21:30:32 -05:00
|
|
|
6. View the `mysite` container's port.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
$ docker port mysite
|
|
|
|
80/tcp -> 0.0.0.0:49166
|
|
|
|
443/tcp -> 0.0.0.0:49165
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2015-02-16 16:24:13 -05:00
|
|
|
7. Open the site in a browser:
|
|
|
|
|
2015-10-09 19:50:41 -04:00
|
|
|
![My site page](images/newsite_view.png)
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2016-02-27 21:30:32 -05:00
|
|
|
8. Add a page to your `$HOME/site` in real time.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
$ echo "This is cool" > cool.html
|
2015-03-17 19:59:59 -04:00
|
|
|
|
2015-02-16 16:24:13 -05:00
|
|
|
9. Open the new page in the browser.
|
|
|
|
|
2015-10-09 19:50:41 -04:00
|
|
|
![Cool page](images/cool_view.png)
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
10. Stop and then remove your running `mysite` container.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-04-29 15:51:57 -04:00
|
|
|
$ docker stop mysite
|
|
|
|
$ docker rm mysite
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2016-01-31 00:08:25 -05:00
|
|
|
> **Note**: There is a [known
|
|
|
|
> issue](https://docs.docker.com/machine/drivers/virtualbox/#known-issues) that
|
|
|
|
> may cause files shared with your nginx container to not update correctly as you
|
|
|
|
> modify them on your host.
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
## Upgrade Docker Toolbox
|
2015-04-29 15:51:57 -04:00
|
|
|
|
2016-02-27 21:30:32 -05:00
|
|
|
To upgrade Docker Toolbox, download and re-run the [Docker Toolbox
|
2015-07-12 10:09:14 -04:00
|
|
|
installer](https://docker.com/toolbox/).
|
2015-04-29 15:51:57 -04:00
|
|
|
|
|
|
|
|
2015-09-11 13:06:54 -04:00
|
|
|
## Uninstall Docker Toolbox
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
To uninstall, do the following:
|
2015-04-29 15:51:57 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
1. List your machines.
|
2015-04-29 15:51:57 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
$ docker-machine ls
|
|
|
|
NAME ACTIVE DRIVER STATE URL SWARM
|
2015-09-11 13:06:54 -04:00
|
|
|
dev * virtualbox Running tcp://192.168.99.100:2376
|
|
|
|
my-docker-machine virtualbox Stopped
|
|
|
|
default virtualbox Stopped
|
2015-04-29 15:51:57 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
2. Remove each machine.
|
2015-04-29 15:51:57 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
$ docker-machine rm dev
|
|
|
|
Successfully removed dev
|
2015-09-11 13:06:54 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
Removing a machine deletes its VM from VirtualBox and from the
|
|
|
|
`~/.docker/machine/machines` directory.
|
2015-04-29 15:51:57 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
3. Remove the Docker Quickstart Terminal and Kitematic from your "Applications" folder.
|
2015-04-29 15:51:57 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
4. Remove the `docker`, `docker-compose`, and `docker-machine` commands from the `/usr/local/bin` folder.
|
2015-04-29 15:51:57 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
$ rm /usr/local/bin/docker
|
2015-09-11 13:06:54 -04:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
5. Delete the `~/.docker` folder from your system.
|
2015-04-29 15:51:57 -04:00
|
|
|
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-09-11 13:06:54 -04:00
|
|
|
## Learning more
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2015-07-12 10:09:14 -04:00
|
|
|
Use `docker-machine help` to list the full command line reference for Docker Machine. For more
|
2016-02-27 21:30:32 -05:00
|
|
|
information about using SSH or SCP to access a VM, see the [Docker Machine
|
2015-07-12 10:09:14 -04:00
|
|
|
documentation](https://docs.docker.com/machine/).
|
2015-02-16 16:24:13 -05:00
|
|
|
|
2016-02-27 21:30:32 -05:00
|
|
|
You can continue with the [Docker Engine User Guide](../userguide/index.md). If you are
|
2015-09-11 13:06:54 -04:00
|
|
|
interested in using the Kitematic GUI, see the [Kitematic user
|
2015-10-09 19:50:41 -04:00
|
|
|
guide](https://docs.docker.com/kitematic/userguide/).
|