My Adventures with Docker Toolbox

What Is Docker Toolbox?

Docker Toolbox is a way to run Docker on Windows or Mac.

Windows Logo

Docker is run within a VirtualBox VM.  In order to interact with the Docker daemon in that VM, command-line executables are added to the path.

Docker Toolbox is a clever way to use Docker on non-Linux machines.  That being said, I’ve had a few hiccups using this tool:

  • Accessing multiple containers’ static IP addresses
  • Copying files from the host into the container

Accessing Static IP Addresses from the Host

I enjoy using docker-compose a lot.  It allows me to launch multiple containers from one yaml file.

I commonly launch multiple web services with docker-compose.  For example, I might have a Jenkins server and an SVN server or Git server all as different services.  I usually assign them static IP addresses so I know how to access them after they launch.  This prevents me from having to lookup their IP addresses.

Ethernet Switch

In this case, Docker does a fantastic job of managing the creation of networks.  I can assign multiple static IPs on the same network that Docker creates for me.

Unfortunately, Docker toolbox does not play nice with this setup.

Since Docker toolbox is within a VM, those networks are not exposed to the host.  It requires a host-only network to be setup, but it also has a NAT network for Internet access within the VM.

Unfortunately, those networks do not allow the host to access the networks created by Docker within that VM.  Adding a bridged network does not help either.

In looking up solutions, there may be a way to manually add routes within the Docker VM.  There may also be some other hacky ways to do this.  But they are just that – hacks.  As far as I know, no one has gracefully solved this problem.

The solution always seems to be to use different ports for all your services.  Not an elegant solution in my opinion.

I believe Docker for Windows has solved that problem.  I’ve been told by a co-worker that multiple static IPs are recognized from the host after starting a docker-compose file.  Unfortunately, I’m not able to use Docker for Windows.

So, for now, I will use different ports rather than IP addresses.

Keep in mind, Docker toolbox has a host-only network in that VM.  If you want to access services from the host, you need to use that IP address.  On my (Windows 10) machine, it is 192.168.99.100.

If anyone has a good solution to this problem, I would love to hear it.  The best I’ve seen are workarounds.

Copy Files from Host to Container

This one is another bit of a problem for several Docker toolbox users.  Specifically, I am focused on mounting a volume from the host to the container.  This shares files between the host and container.

Files

Fortunately, I have been able to resolve this one.

By default, the only shared folder is C:/Users in the VM settings of Docker toolbox.

This had two problems for me:

  • I want to share the entire C:/ drive.
  • I generally work in a Cygwin terminal.

It helps to know what is happening when you try to mount a volume using Docker toolbox.

With Docker running on Linux, you are just sharing files between the host and container.

Contrast that with Docker toolbox, where there is an extra layer.  You first share files with the VM, which then shares files with the container.

This means when you mount a volume, you need to know where that is in the VM.

For example, let’s say you are running a Docker command from C:/MyCoolDir, and you mount volume “test” from the host.  That means there should be a C:/MyCoolDir/Test directory on the host.

Where is that within the VM?

Well, by default, the C:/ drive is not shared in the VM.  And that path is going to be passed as something like C:/… or c/… to the VM.

My solution to this was to modify the Docker Toolbox’s VM settings.

These are my drive mappings:

  • C:\ -> /cygdrive/c
  • C:\ -> C:
  • C:\ -> c

That’s right: I have three mappings all for the C: drive on my computer.

That being said, I can now share volumes whether I launch Docker from a command prompt or within Cygwin.  Both places work.

This is a common problem that several Docker toolbox users have (based on Google searches I’ve done).  It’s a relatively simple fix.  I recommend just using those same shared folder settings that I’ve given above.

If you need a path to a different drive, perhaps you can use those same mappings, just replacing the drive letter.

For what it’s worth, I haven’t tried any of this on a Mac.  So I apologize if you’re looking for Mac-specific advice.

Conclusion

I appreciate Docker having the ability to work on Windows and Mac.  Docker toolbox (and Docker for Windows) are very useful tools.

Unfortunately, there are quite a few gotchas here and there.  One of the big goals of Docker is to share a common environment on multiple platforms.  While this is definitely achievable on Linux, it’s still a tossup on Windows and Mac.  These small differences may make one docker-compose file work on Linux but not in Docker toolbox.

That being said, I’m sure the future will bring great new improvements to make this more reliable.  Maybe not with Docker toolbox, but perhaps with other tools.  In the meantime, hopefully these suggestions can help make it as consistent as possible.

Please follow and like us:
error

2
Leave a Reply

avatar
1 Comment threads
1 Thread replies
2 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
tscottBuildingTheApp Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
BuildingTheApp
Guest
BuildingTheApp

Finally , thank you. Everything helped with Windows 10 host and Linux containers on a default bridge network, running in Docker Toolbox (Oracle VM)