Developer Bliss with Docker for Mac & Docker for Windows 11


docker-logo-240I’m a huge fan of Docker and am using it a lot in various projects now. In fact the https://blog.codewithdan.com site is running in Docker containers on Azure. Three containers are used and managed with Docker Cloud:

  1. nginx container
  2. WordPress container
  3. MariaDB (MySql) container

What’s great about Docker is that I can have a local version of my blog up and running on my dev machine in a matter of minutes and it mirrors production. That makes it easy to test out various WordPress changes (plugin and theme updates for example) rather than trying them on my production server which can be scary! If you’re working in an enterprise environment this capability is especially useful with Line of Business apps that may require a lot of moving parts such as a reverse proxy, one of more running web servers, databases, caching servers, etc.

If you’re new to Docker, getting started with it has always been pretty straightforward using Docker Toolbox, but with Docker for Mac and Docker for Windows getting started with Docker is even easier now! With Docker Toolbox you have to use Docker Machine to get VirtualBox up and running and “linked” into a command window on Mac or Windows. That’s fairly easy to do actually but does require more upfront work (albeit minimal). With Docker for Mac and Docker for Windows it’s even easier and also more efficient to run on your dev box.

Key Benefits of Docker for Mac and Docker for Windows

Docker for Mac and Docker for Windows provide several key benefits especially to developers using Docker in their workflow:

  • Faster and more efficient (more native and lightweight compared to VirtualBox)
  • OS level integration that leverages native networking, virtualization and file system features
  • Use the localhost network to access containers
  • Auto-update as new releases come out
  • Run Docker commands from any command-line window
  • File change notifications (used with volumes) work consistently (which is great for devs using containers to do local development)

Both the Mac and Windows apps use OS-optimized virtualization services including xhyve on Mac and Hyper-V on Windows. You won’t have to worry about using Docker Machine to setup the environment (as mentioned earlier) but can still use standard Docker Client commands as well as Docker Compose commands in any command window. You can also easily restart the VM and configure it (CPUs, memory, etc.) by clicking on the icon in the toolbar on Mac or tray on Windows:

Docker for Mac

dockerMac

 

Docker for Windows

dockerWindows

 

On Mac you can go to Preferences to set the number of CPUs and amount of memory you’d like the underlying VM use:

dockerMacPrefs

 

Windows provides a Settings option:

dockerWindowsPrefs

 

Docker for Mac and Docker for Windows make it even easier to get started using Docker on your development machine.  Since it’s lightweight and fast I have it setup to automatically start as I login and keep it up and running on my machine. What’s really nice is that once it’s installed on your dev box you can open a command window and use Docker directly without any additional configuration:


dockerExample

If you haven’t looked into Docker yet, there’s no time like the present. Once you understand how it works you’ll find that it’s quite amazing and great to add into your development workflow (definitely my favorite technology over the past few years). If you’d like to learn more about Docker from a developer standpoint check out my Docker for Web Developers course on Pluralsight!

dockerForWebDevs

  • Docker is indeed a great technology, but it also changes the way we/things work.
    There are still a few concepts that I haven’t figured out the answer to, ie:
    How are the files of your wordpress and mariadb dockers images persisted?

    • Docker for Mac now has `osxfs` or what. What matters is that it now has fs events updates, so docker knows and updates the files as they are updated on the Mac. Also the ownership issues are solved with that. I don’t know how it works. But it works. On a Mac. Making Docker good for development finally. 🙂

      • I also see “Shared Drives” now in the new Windows client for docker.
        But my question was more specific to how Dan does it for his images. I guess as long as you don’t destroy the docker container that data is safe within the container?

    • Hi David. When I’m on my local box I use volumes to point a container path to my local source code (I define the volume in my docker compose YAML file). That way I don’t have to keep re-building the image and re-creating the container every time I make a source code change. When I’m ready to move the image somewhere I have a separate “production” version of my dockerfiles that uses the COPY command to copy the source code into the image. I then use Docker Cloud to get the images up and running as containers on my cloud VM.

      The “production” container for MariaDB has a volume that persists the data to the host. Especially important for that container since I need the data to stick around if I redeploy a new version of the image and container of course.

      If you have Pluralsight.com subscription (or want to check out their trial – up to 200 minutes of free courses), I have a new “Docker for Web Developers” course that goes through everything:

      https://www.pluralsight.com/courses/docker-web-development

      • Thanks Dan. Much more clear now.
        I have pluralsight, so I’ll add your course to my list… which is only getting longer.
        Maybe it’s time for a new .NET Rocks episode? 🙂

        • Glad that helped. I’ll have to talk with Carl and Richard about doing another episode. 🙂

          • rohan

            your PS web development with docker course is just too good. Rock solid foundation laid out in the course. had earlier spent hours and days to understand docker. but this was a breeze.

      • James McLean

        Firstly thanks for the course “Docker for Web Developers” (and all the others you’ve created). It really has helped me grasp things a lot better.

        The one thing that’s got me really stuck (and I’m hoping you might be able to offer some guidance), from a development perspective is the issue of permissions for mounted host volumes -> container.

        So using Docker for Windows, I have a nice standard containerized LAMP stack and my docker-compose file mounts my code files into /var/www/html so I can edit my code files on my host (similar worklow to yours by the sounds of it) and those changes are there in the container.

        The issue is that all file permissions are taken from the host. If I want to test that my web application can upload a file, create a directory, etc it’s instantly denied because my mounted volume is automatically set to root:root ownership.

        Any suggestions on how to fix / circumvent this issue?

        • Hi James. Glad you enjoyed the course – thanks.

          I haven’t tried to do exactly what you’re doing there. Normally I set the proper permissions in the image via chmod on the folder/file. But, I’ve never tried tweaking the permissions on a Windows box volume. If I come across any additional info I’ll let you know.

          • James McLean

            Thanks Dan, much appreciated. Our vagrant setup works (and works well). It allows us to easily build a new local dev VM when required and use NFS (winnfsd) to mount and sync files between guest and host with testable permissions, however the reduced overheads and speed from docker and the capability to push the entire app (with little to no alteration) to production is undeniably attractive. Thanks again.