Lecture
In most cases, a Dockerfile created for Linux will work on macOS without changes. But there are important nuances to keep in mind.
On macOS, Docker Desktop runs a Linux virtual machine (LinuxKit / Alpine / Fedora CoreOS), inside which the containers actually run.
That is, your container still runs in a Linux environment, even on a Mac.
Therefore:
✔ images like ubuntu, debian, alpine, centos, etc. will work the same way
✔ a Dockerfile with Linux commands will also work
✔ there are almost no differences inside the container itself
On Linux:
-v /home/user/project:/app
On Mac:
-v /Users/username/project:/app
Different paths — different FS — sometimes slower, but it works.
Mac M1/M2/M3 = ARM64
Linux PC = x86_64
If the image was built for amd64 and the Mac is ARM, errors may occur.
Use multi-arch or force the architecture:
docker build --platform=linux/amd64 -t myimage .
or
FROM --platform=$BUILDPLATFORM node:20
If your Dockerfile:
installs packages with architecture-dependent binaries
builds Go/Rust/C/C++ for the host
uses pip wheels or npm modules with native extensions
→ problems may occur if the architecture is ARM.
Solutions:
add --platform=linux/amd64 to the build flags
use multi-arch images (most official images support ARM64)
rebuild dependencies inside the container
Especially if:
there are many files in a bind mount
heavy I/O
But this is not a compatibility issue, just a fact.
Yes, a Dockerfile written for Linux installs and works on macOS almost always without changes, because the containers still run inside a Linux VM.
But you need to take into account:
the difference in architectures (ARM vs AMD64)
file paths
native dependencies
performance
Comments