You can use Docker Machine to:
Docker(is an open-source project to easily create lightweight, portable, self-sufficient containers from any application. The same container that a developer builds and tests on a laptop can run at scale, in production, on VMs, bare metal, OpenStack clusters, public clouds and more.
- Install and run Docker on Mac or Windows
- Provision and manage multiple remote Docker hosts
- Provision Swarm clusters
What is Docker Machine?
- Before continuing, make sure your computer supports hardware virtualization.
- Before we can make any changes to the Docker virtual machine image, we need to stop Docker for Mac. There should be a Docker for Mac icon in the menu bar. You should see something similar to this: You can also check via the command line via the ps -ef grep -i com.docker.
Docker Machine is a tool that lets you install Docker Engine on virtual hosts, and manage the hosts with docker-machine
commands. You can use Machine to create Docker hosts on your local Mac or Windows box, on your company network, in your data center, or on cloud providers like AWS or Digital Ocean.
Using docker-machine
commands, you can start, inspect, stop, and restart a managed host, upgrade the Docker client and daemon, and configure a Docker client to talk to your host.
Point the Machine CLI at a running, managed host, and you can run docker
commands directly on that host. For example, run docker-machine env default
to point to a host called default
, follow on-screen instructions to complete env
setup, and run docker ps
, docker run hello-world
, and so forth.
Why should I use it?
Machine is currently the only way to run Docker on Mac or Windows, and the best way to provision multiple remote Docker hosts on various flavors of Linux.
Docker Machine has these two broad use cases.
I want to run Docker on Mac or Windows
If you work primarily on a Mac or Windows laptop or desktop, you need Docker Machine in order to “run Docker” (that is, Docker Engine) locally. Installing Docker Machine on a Mac or Windows box provisions a local virtual machine with Docker Engine, gives you the ability to connect it, and run
docker
commands.I want to provision Docker hosts on remote systems
Docker Engine runs natively on Linux systems. If you have a Linux box as your primary system, and want to run docker
commands, all you need to do is download and install Docker Engine. However, if you want an efficient way to provision multiple Docker hosts on a network, in the cloud or even locally, you need Docker Machine.
Whether your primary system is Mac, Windows, or Linux, you can install Docker Machine on it and use docker-machine
commands to provision and manage large numbers of Docker hosts. It automatically creates hosts, installs Docker Engine on them, then configures the docker
clients. Each managed host (“machine”) is the combination of a Docker host and a configured client.
What’s the difference between Docker Engine and Docker Machine?
When people say “Docker” they typically mean Docker Engine, the client-server application made up of the Docker daemon, a REST API that specifies interfaces for interacting with the daemon, and a command line interface (CLI) client that talks to the daemon (through the REST API wrapper). Docker Engine accepts docker
commands from the CLI, such as docker run <image>
, docker ps
to list running containers, docker images
to list images, and so on.
Docker Machine is a tool for provisioning and managing your Dockerized hosts (hosts with Docker Engine on them). Typically, you install Docker Machine on your local system. Docker Machine has its own command line client docker-machine
and the Docker Engine client, docker
. You can use Machine to install Docker Engine on one or more virtual systems. These virtual systems can be local (as when you use Machine to install and run Docker Engine in VirtualBox on Mac or Windows) or remote (as when you use Machine to provision Dockerized hosts on cloud providers). The Dockerized hosts themselves can be thought of, and are sometimes referred to as, managed “machines”.
Where to go next
- Create and run a Docker host on your local system using VirtualBox
- Provision multiple Docker hosts on your cloud provider
Edit this page, file a ticket, or rate this page:
Estimated reading time: 4 minutes
Docker Desktop for Mac provides several networking features to make iteasier to use.
Features
VPN Passthrough
Docker Desktop for Mac’s networking can work when attached to a VPN. To do this,Docker Desktop for Mac intercepts traffic from the containers and injects it intoMac as if it originated from the Docker application.
Port Mapping
When you run a container with the -p
argument, for example:
Docker Desktop for Mac makes whatever is running on port 80 in the container (inthis case, nginx
) available on port 80 of localhost
. In this example, thehost and container ports are the same. What if you need to specify a differenthost port? If, for example, you already have something running on port 80 ofyour host machine, you can connect the container to a different port:
Now, connections to localhost:8000
are sent to port 80 in the container. Thesyntax for -p
is HOST_PORT:CLIENT_PORT
.
HTTP/HTTPS Proxy Support
See Proxies.
Known limitations, use cases, and workarounds
Following is a summary of current limitations on the Docker Desktop for Macnetworking stack, along with some ideas for workarounds.
There is no docker0 bridge on macOS
Because of the way networking is implemented in Docker Desktop for Mac, you cannot see adocker0
interface on the host. This interface is actually within the virtualmachine.
I cannot ping my containers
Docker Desktop for Mac can’t route traffic to containers.
Docker Mac Virtual Machines
Per-container IP addressing is not possible
The docker (Linux) bridge network is not reachable from the macOS host.
Use cases and workarounds
There are two scenarios that the above limitations affect:
I want to connect from a container to a service on the host
The host has a changing IP address (or none if you have no network access). We recommend that you connect to the special DNS namehost.docker.internal
which resolves to the internal IP address used by thehost. This is for development purpose and will not work in a production environment outside of Docker Desktop for Mac.
You can also reach the gateway using gateway.docker.internal
.
If you have installed Python on your machine, use the following instructions as an example to connect from a container to a service on the host:
Run the following command to start a simple HTTP server on port 8000.
python -m http.server 8000
If you have installed Python 2.x, run
python -m SimpleHTTPServer 8000
.Now, run a container, install
curl
, and try to connect to the host using the following commands:
I want to connect to a container from the Mac
Port forwarding works for localhost
; --publish
, -p
, or -P
all work.Ports exposed from Linux are forwarded to the host.
Our current recommendation is to publish a port, or to connect from anothercontainer. This is what you need to do even on Linux if the container is on anoverlay network, not a bridge network, as these are not routed.
The command to run the nginx
webserver shown in Getting Startedis an example of this.
To clarify the syntax, the following two commands both expose port 80
on thecontainer to port 8000
on the host:
To expose all ports, use the -P
flag. For example, the following commandstarts a container (in detached mode) and the -P
exposes all ports on thecontainer to random ports on the host.
See the run command for more details onpublish options used with docker run
.