- Run Docker For Windows
- Docker On Windows Server
- Learning Docker For Windows On Mac Windows 10
- Using Docker On Mac
Docker for Mac / Docker for Windows (Docker Desktop) Pros. Offers the most “native” experience, you can easily use any terminal you you want since Docker is effectively running on localhost from macOS / Windows’ POV. Docker is heavily developing and polishing this solution. The original solution to running Docker on OS X and Windows was Docker Toolkit. This was actually a Linux virtual machine running in the VirtualBox Hypervisor. The VM had Docker installed and could run containers. Docker Desktop for Mac still makes use of a virtual machine running Linux running in the HyperKit Hypervisor. Windows Docker Machine. This Vagrant environment creates a 'Docker Machine' to work on your MacBook with Windows containers. You can easily switch between Docker Desktop Linux containers and the Windows containers. Docker is an open-source project that automates the deployment of applications inside software containers, by providing an additional layer of abstraction and automation of operating-system-level virtualization on Linux, Mac OS and Windows (read more on Wikipedia).
Estimated reading time: 5 minutes
Docker Desktop for Mac is the Community version of Docker for Mac.You can download Docker Desktop for Mac from Docker Hub.
By downloading Docker Desktop, you agree to the terms of the Docker Software End User License Agreement and the Docker Data Processing Agreement.
System requirements
Your Mac must meet the following requirements to successfully install Docker Desktop:
Mac hardware must be a 2010 or a newer model with an Intel processor, with Intel’s hardware support for memory management unit (MMU) virtualization, including Extended Page Tables (EPT) and Unrestricted Mode. You can check to see if your machine has this support by running the following command in a terminal:
sysctl kern.hv_support
If your Mac supports the Hypervisor framework, the command prints
kern.hv_support: 1
.macOS must be version 10.14 or newer. That is, Mojave, Catalina, or Big Sur. We recommend upgrading to the latest version of macOS.
If you experience any issues after upgrading your macOS to version 10.15, you must install the latest version of Docker Desktop to be compatible with this version of macOS.
Note
Docker supports Docker Desktop on the most recent versions of macOS. That is, the current release of macOS and the previous two releases. As new major versions of macOS are made generally available, Docker stops supporting the oldest version and supports the newest version of macOS (in addition to the previous two releases). Docker Desktop currently supports macOS Mojave, macOS Catalina, and macOS Big Sur.
At least 4 GB of RAM.
VirtualBox prior to version 4.3.30 must not be installed as it is not compatible with Docker Desktop.
What’s included in the installer
The Docker Desktop installation includes Docker Engine, Docker CLI client, Docker Compose, Notary, Kubernetes, and Credential Helper.
Install and run Docker Desktop on Mac
Double-click
Docker.dmg
to open the installer, then drag the Docker icon to the Applications folder.Double-click
Docker.app
in the Applications folder to start Docker. (In the example below, the Applications folder is in “grid” view mode.)The Docker menu in the top status bar indicates that Docker Desktop is running, and accessible from a terminal.
If you’ve just installed the app, Docker Desktop launches the onboarding tutorial. The tutorial includes a simple exercise to build an example Docker image, run it as a container, push and save the image to Docker Hub.
Click the Docker menu () to seePreferences and other options.
Select About Docker to verify that you have the latest version.
Congratulations! You are now successfully running Docker Desktop.
If you would like to rerun the tutorial, go to the Docker Desktop menu and select Learn.
Automatic updates
Starting with Docker Desktop 3.0.0, updates to Docker Desktop will be available automatically as delta updates from the previous version.
Run Docker For Windows
When an update is available, Docker Desktop automatically downloads it to your machine and displays an icon to indicate the availability of a newer version. All you need to do now is to click Update and restart from the Docker menu. This installs the latest update and restarts Docker Desktop for the changes to take effect.
Uninstall Docker Desktop
To unistall Docker Desktop from your Mac:
- From the Docker menu, select Troubleshoot and then select Uninstall.
- Click Uninstall to confirm your selection.
Note: Uninstalling Docker Desktop will destroy Docker containers and images local to the machine and remove the files generated by the application.
Save and restore data
You can use the following procedure to save and restore images and container data. For example to reset your VM disk:
Use
docker save -o images.tar image1 [image2 ...]
to save any images you want to keep. See save in the Docker Engine command line reference.Use
docker export -o myContainner1.tar container1
to export containers you want to keep. See export in the Docker Engine command line reference.Uninstall the current version of Docker Desktop and install a different version (Stable or Edge), or reset your VM disk.
Use
docker load -i images.tar
to reload previously saved images. See load in the Docker Engine.Use
docker import -i myContainer1.tar
to create a filesystem image corresponding to the previously exported containers. See import in the Docker Engine.
For information on how to back up and restore data volumes, see Backup, restore, or migrate data volumes.
Where to go next
- Getting started provides an overview of Docker Desktop on Mac, basic Docker command examples, how to get help or give feedback, and links to other topics about Docker Desktop on Mac.
- Troubleshooting describes common problems, workarounds, howto run and submit diagnostics, and submit issues.
- FAQs provide answers to frequently asked questions.
- Release notes lists component updates, new features, and improvements associated with Docker Desktop releases.
- Get started with Docker provides a general Docker tutorial.
TL;DR summary
If you are using Docker Toolbox then you may have noticed that data volumes mapped to local directories on the Mac (using the -v
option of the docker run
command) do not see changes made to the local files. I have developed a workaround using rsync
. See the GitHub repo https://github.com/JeNeSuisPasDave/asd-sync-src-to-container for examples of the workaround.
The use case for sharing local files with a Docker container
My main use case, currently, for Docker containers is to test code written to run on Linux servers. My development system is a Mac, still running El Capitan (OS X 10.11). I want to write code using Sublime Text 3 on my Mac, share that code with a Docker container using a data volume, and build and test the code in the container. I want to iterate through many edit-build-test cycles using that setup.
Using Docker Toolbox
On a Mac there are, currently, two choices for hosting Docker containers. The original mechanism was to host a Linux VM using VirtualBox. This environment is well supported with Docker Toolbox—which includes a version of Docker Engine that works on the Mac and also includes Docker Machine, a utility used to create and manage VirtualBox Linux VMs that host a proper Docker environment. The VMs created by Docker Machine use the Boot2Docker distribution, a lightweight Linux system intended specifically to run Docker containers in a development environment.
The VMs created by Docker Machine share the host’s /Users
folder with full access. This allows the mapping of any directory or file in the /Users
tree to be mapped to a Docker data volume. For example, if I wanted to map my project source code to a /src
folder in the container, I could do something like this:
In that case I’m mapping my local ~/src
directory to a new directory /src
in the container. After the container is instantiated, the /src
folder will be mounted and the build-and-test.sh
script will be executed.
But there is a problem
Docker On Windows Server
The problem with this setup is that I can’t do any file watching. That is, once data volume is established then the container won’t see any changes to the host directory. This is a problem if I’m doing web development and want to keep a container-hosted web server up and running while I tweak CSS and JavaScript files on the Mac. If I change those files on the Mac, the web server will still be seeing the old content.
Even if I shut down and remove the container, the next time I run the container it will continue to see the file content that existed the first time I created a data volume mapped to the $PWD/src
directory. To get containers seeing any updated content I have to reboot the Docker VM.
I don’t fully understand why this happens, why the Docker VM is apparently caching content from shared host folders and why the cache isn’t being updated. But it has something to do with inotify not being supported by VirtualBox. If an editor changes a file, the new file will often end up with a different inode that the original version. File watching mechanisms listen for inotify events to discover such changes. But VirtualBox does not propogate inotify events on the host to guest VMs (see ticket #10660). Enough people run into this problem (see [issue #15793][15793]) that it seems like Docker should document the issue prominently; it does not.
I have a workaround for the problem (spoiler: it involves rsync
), but first let me address the obvious solution.
Using Docker for Mac
It seems obvious that the inotify problem with using VirtualBox to host containers would be elminated by using Docker for Mac. No VMs, no VirtualBox, just native containers.
Unfortunately, there are performance problems with data volumes mapped to host directories. Data access is measured at 10 to 20 times slower than data volume containers. This issue was reported in March 2016 and is still a problem now, in November 2016.
This isn’t the only issue with Docker for Mac. The product remains a beta, and I’ve got enough learning to do on containers to want to avoid adding a beta implementation to the mix. So I’m sticking with a Linux hosted Docker for now, and that means finding a way around the VirtualBox inotify problem.
Solution: A workaround for lack of inotify propogation
The basic idea is to use an intermediate directory on the Docker VM, and use rsync
to keep that directory up to date with the latest files and changes of the local directory on the Mac.
Any time you change files on the Mac, you will invoke rsync
to push those changes to the intermediate directory hosted on the Docker VM. Any container hosted on the Docker VM and having a transient data volume mapped to the intermediate directory will get the inotify events and will see the changed files. See the sync-to-host-mapped-dv
example in the https://github.com/JeNeSuisPasDave/asd-sync-src-to-container repository for example scripts that do just that.
If you have a data volume container, then two synchronization operations are required: the rsync
from Mac to Docker VM directory, and then a second rsync
to transfer files and changes from the Docker VM intermediate directory to the data volume container. See the sync-to-dv-container
example in the https://github.com/JeNeSuisPasDave/asd-sync-src-to-container repository for example scripts that keep a data volume container synchronized with a local directory on the Mac.
In the fully functional examples of the GitHub repo, the run.sh
script is used first. It establishes and populates the intermediate directory, establishes and populates the data volume container (if you are using one), and launches the “work” container with attached data volumes.
Learning Docker For Windows On Mac Windows 10
From that point on you run refresh.sh
script anytime you have changed files on the host that you want to propogate to the container.
Taking the solution further
- You could add invocation of
refresh.sh
script to your editor (e.g. using a build system configuration in Sublime Text 3). - You could automate the execution of
refresh.sh
so that it is triggered by file system changes on the Mac … using, for example:- the Python package watchdog to monitor directories and files for changes, triggering
refresh.sh
when the changes are detected) - Hazel to monitor folders and trigger
refresh.sh
when changes happen - Folder Actions and Automator
- the Python package watchdog to monitor directories and files for changes, triggering
Using Docker On Mac
Caveat: I’ve not tried any of the above automations (read: don’t ask me for help with them). For the moment I’m happy to just type refresh.sh
when needed.