Docker Community Forums

Share and learn in the Docker community.

What is the relationship between running a docker container and creating a docker machine?

(Draav) #1

My assumption was that when you use docker run and image is taken and turned into a running container. That container is running on a virtual machine that was created by docker-machine create. However I can create containers using docker run without having ever created a docker machine.

I am asking because I am trying to follow a tutorial where the presenter runs a process that is accepting information on a port. He executes:

docker run --rm -ti -p 45678:45678 -p 45679:45679 --name echo-server ubuntu:14.04 bash

then inside the container:

nc -lp 45678 | nc -lp 45679

Then in a different terminal he uses docker-machine ip and recieves and ip address (later on he creates another container to relay the output to, but i didn’t get that far). However I just get “Error: No machine name(s) specified and no “default” machine exists”.

I see that I can create a machine using virtualbox or whatever other software, but how is that related to the container I just created? How am I running this container with no machine? Is there a hidden machine that I am running it on or are there multiple ways to run containers? If there is no machine, how do I get the IP address of the container?

Thanks, just getting started with this stuff, hope this is the right area to ask this question.

(David Maze) #2

Are you using “Docker for Mac” or “Docker Toolbox”? Is there a whale icon on your menu bar?

The not-toolbox “Docker for Mac” product tries hard to hide the VM (it is there in reality, but it’s tricky to get at) and it doesn’t interact with docker-machine at all. When you run

you can access those published ports from the host on the localhost IPv4 address

(Draav) #3

Ah, using worked, thanks!

There is a whale icon in the menu bar. I assume that means that I’m using Docker for Mac then correct?

Would that mean I won’t be using docker-machine for anything? And I can just pretend that there is no virtual machine and assume everything is running on my local IP as if I was using Docker on Linux?

Does this limit any functionalities that were previously available with docker machine? Is there any reason I won’t want to use docker-machine for anything?

(David Maze) #4


…that’s the theory…

A quick glance through the forum should find you much longer threads on both of these, but the three big issues I’m aware of:

  • If your workflow depends on bind-mounting (docker run -v) large amounts of data from the host system into the container (like your entire application) you may find Docker for Mac slow and unstable; but if you docker build your application it works fine
  • If your workflow depends on --net=host, whatever you’re expecting from it probably won’t work
  • If your workflow depends on a fixed container-visible IP address for the host, or specific host-visible IP addresses for containers, this won’t work

I tend to actually use docker-machine still, either because (2) our whole-application deployment uses a Consul-based setup that depends on --net=host, or (3) a test framework assumes that there exists a single IP address that both the host and all of the containers can use to reach the containers ( on Linux, on Machine) and it just isn’t there.

(Draav) #5

Thank you so much for the answer they help a lot with me figuring out where to look for more in depth information. And where to begin my searches.

So there shouldn’t be any issue with just using docker-machine still even though I have Docker for Mac? I can create a docker-machine using virtualbox still and would be able to more accurately follow along with most tutorials I see?

A last question would be, if I was using the Docker Toolbox, would that mean that the docker machine would need to be (visibly) created? Like I would not be able to start a container without there being a docker-machine active? I assume that one is created by default, but it would still need to be there right?

(David Maze) #6

Correct. You can even have both running; eval $(docker-machine env default) will use your Machine VM, and eval $(docker-machine env -u) will switch back to the Docker for Mac version.

You definitely need to manually manage the docker-machine VM if you’re using that path. I don’t totally know what Docker Toolbox does on installation, but a default docker-machine create is pretty straightforward if one isn’t created for you.