Switching Docker to Windows Containers on a Mac

Running Docker on macOS and Windows: Containers, Configuration and Troubleshooting

This guide covers the hands-on side of running Docker across macOS and Windows — from toggling between Windows and Linux containers to troubleshooting compose services and reaching services that run on your host machine. Whether you are standing up SQL Server in a container or swapping Docker Desktop for minikube, the notes below address the usual pain points.

Getting Started with Docker Desktop

Once you launch the Docker application, the first step is to configure it to host SQL Server inside a container. Start by installing the Docker-Microsoft PackageManagement Provider module from the PowerShell Gallery. If minikube is your preference, launch it with a VM driver instead of the docker driver — hyperkit on macOS or hyperv on Windows, for instance.

In the past, the original way to run Docker on OS X and Windows was Docker Toolkit. Docker-for-Mac operates by running a Linux VM underneath (via hyperkit) and creating containers within that VM. Docker Toolbox is still an option when you cannot run Docker for Mac or Docker for Windows.

  • Install the PackageManagement provider from the PowerShell Gallery
  • Start minikube with a VM driver such as hyperkit or hyperv
  • Use Docker Toolbox when Docker Desktop is not available

Switching Between Windows and Linux Containers

When Docker for Windows is running with Windows containers selected, you can run Windows and Linux containers simultaneously. To switch, right-click the Docker service and pick Switch to Windows Containers. You can also do it from the command line by typing "%programfiles%\docker\docker\dockercli" -SwitchDaemon.

A frequent issue is being unable to pull a Windows image because the Docker runtime is set to Linux with no visible option to change it. If Docker Desktop worked before but won't start after a reboot, inspect the diagnostics logs. When switching to Windows containers triggers a crash, review the stacktrace and log files.

  • Right click the Docker service and select Switch to Windows Containers
  • Use the dockercli -SwitchDaemon command as an alternative
  • Confirm the runtime matches the image platform you need

Line Endings and Build Scripts

Open build.sh in VS Code and check the bottom-right corner of the window. Click CRLF and the command palette appears, letting you choose between CRLF and LF. Picking the correct line ending prevents build failures when scripts travel between Windows and Unix environments.

If a file has turned read-only, clear the Read-Only checkbox and click Apply. For log files like panic.log, right-click the file, open Properties, and change the read-only attribute before trying again.

Debugging Compose Services and Platform Settings

Open a PowerShell prompt in the solutions root folder — the one containing the docker-compose.yml file — and run docker run to launch a container. If a service acts up, try debugging your docker-compose container directly inside Visual Studio.

When working across architectures, set the platform property in docker-compose.yml, for example platform: "linux/arm64". Docker has long supported multi-platform images, so you can build and run both x86 and Arm images on Docker Desktop. Recent releases let developers build and run end-to-end on Arm, from Docker Desktop on M1-powered Macs to Arm-based cloud servers such as AWS Graviton 2.

Connecting to Host Services from Containers

If Redis is running on your localhost and you want a container to reach it without adding another Redis service to docker-compose, use the host address that matches your platform.

  • Docker for Mac: use host.docker.internal
  • Docker for Windows: use host.docker.internal
  • Docker for Linux: see the platform references for the correct host address

Docker-for-Mac allows connections to containers over Layer 4 (port binding) but not Layer 3 (by IP address). Both the -v flag and file sharing let you share files with a container when you run docker run.

Networking Options

If you know Hyper-V, the transparent network is the easiest option. Container-to-container traffic on a single node, container-to-external traffic on single or multi-node setups, and bridged connections through a Hyper-V virtual switch are all supported. In cross-subnet scenarios the container MAC address is rewritten on ingress and egress and routed accordingly. Keep in mind that the container MAC address is not static.

Managing Images, Containers and Subscriptions

If you make a minor code change and rebuild an image that bundles a large NLP model, pushing to Docker Hub can take a long time. Think about how you layer and cache the model so only the changed layers get pushed. Docker announced a new subscription plan for Docker Desktop on Aug. 31, 2022, so review the plan details for your use case.

To import a container to a new host, copy it over and use the appropriate cmdlet. You can also create and start a container with a mounted volume and run a build inside it, for example:

  • docker create -it --name winbuildextended -v ${pwd}:c:/app 4tecture/winbuilddemoenv:latest
  • docker start winbuildextended
  • docker exec winbuild msbuild c:\app\ConsoleDemoExtended.sln

To install Docker Desktop silently from PowerShell, use Start-Process '.\win\build\Docker Desktop Installer.exe' -Wait install. From the Windows Command Prompt, use start /w "" "Docker Desktop Installer.exe" install.

Security, Proxies and SSH

Some Docker runtime security options are currently unsupported and won't work with the Docker driver, including userns-remap. On macOS, containers may hang and require a restart of Docker for Desktop. Proxy configuration is available on both Mac and Windows, and SSH agent forwarding is supported on Mac and Linux.

If you use tools such as Apache Maven that expect DOCKER_HOST and DOCKER_CERT_PATH environment variables, set them to connect to Docker instances through Unix sockets. Containers can also install only the extensions a task needs and switch tool-chains by connecting to a new container.

Container Storage and Isolation

Containers let you run software in an isolated environment. WWT containers are guaranteed not to leak and are well suited to on-site storage. Remember that packing too much into a Docker image can erode the advantages Docker offers.

Related Reading

Getting comfortable with both container platforms comes down to knowing where each setting lives. Confirm which runtime Docker Desktop is using before you pull an image, keep your line endings consistent between Windows and Unix, and use the host address that matches your platform when a container needs to reach a local service. Working through these basics first makes the trickier networking and build scenarios far easier to diagnose.