Understand permission requirements for Docker Desktop on Mac
This page contains information about the permission requirements for running and installing Docker Desktop on Mac.
It also provides clarity on running containers as
root
as opposed to having
root
access on the host.
Permission requirements link
Docker Desktop for Mac is run as an unprivileged user. However, certain functionalities are required for Docker Desktop to perform a limited set of privileged configurations such as:
-
Installing symlinks
in
/usr/local/bin. -
Binding privileged ports
that are less than 1024. The so-called "privileged ports" are not generally used as a security boundary, however operating systems still prevent unprivileged processes from binding them which breaks commands like
docker run -p 127.0.0.1:80:80 docker/getting-started. -
Ensuring
localhostandkubernetes.docker.internalare defined in/etc/hosts. Some old macOS installs don't havelocalhostin/etc/hosts, which causes Docker to fail. Defining the DNS namekubernetes.docker.internalallows Docker to share Kubernetes contexts with containers. - Securely caching the Registry Access Management policy which is read-only for the developer.
Depending on which version of Docker Desktop for Mac is used, privileged access is granted either during installation, first run, or only when it's needed.
From version 4.18 and later, Docker Desktop for Mac provides greater control over functionality that's enabled during installation.
The first time Docker Desktop for Mac launches, you are presented with an installation window where you can choose to either use the default settings, which work for most developers and require privileged access to be granted, or use advanced settings.
If you work in an environment with elevated security requirements, for instance where local administrative access is prohibited, then you can use the advanced settings to remove the need for granting privileged access. You can configure:
- The location of the Docker CLI tools either in the system or user directory
- The default Docker socket
- Privileged port mapping
Depending on which advanced settings you configure, you must enter your password to confirm.
You can change these configurations at a later date from the Advanced page in Settings .
Versions 4.15 to 4.17 of Docker Desktop for Mac don't require the privileged process to run permanently. Whenever elevated privileges are needed for a configuration, Docker Desktop prompts you with information on the task it needs to perform. Most configurations are applied once, subsequent runs don't prompt for privileged access anymore. The only time Docker Desktop may start the privileged process is for binding privileged ports that aren't allowed by default on the host OS.
Versions prior to 4.15 of Docker Desktop for Mac require
root
access to be granted on the first run. The first time that Docker Desktop is launched you receive an admin prompt to grant permission for the installation of the
com.docker.vmnetd
privileged helper service. For subsequent runs,
root
privileges aren't required. Following the principle of least privilege, this approach allows
root
access to be used only for the operations for which it's absolutely necessary, while still being able to use Docker Desktop as an unprivileged user.
All privileged operations are run using the privileged helper process
com.docker.vmnetd
.
Installing symlinks link
The Docker binaries are installed by default in
/Applications/Docker.app/Contents/Resources/bin
. Docker Desktop ensures the Docker CLI is on your PATH without having to reconfigure shells, log out then log back in for example. As on most systems
/usr/local/bin
is on the PATH by default, and so Docker Desktop creates symlinks for all Docker binaries in it.
With version 4.18 and later, you can choose whether to install symlinks either in
/usr/local/bin
or
$HOME/.docker/bin
during installation of Docker Desktop.
If
/usr/local/bin
is chosen, and this location is not writable by unprivileged users, Docker Desktop requires authorization to confirm this choice before the symlinks to Docker binaries are created in
/usr/local/bin
. If
$HOME/.docker/bin
is chosen, authorization is not required, but the you must
manually add
$HOME/.docker/bin
to their PATH.
You are also given the option to enable the installation of the
/var/run/docker.sock
symlink. Creating this symlink ensures various Docker clients relying on the default Docker socket path to work without additional changes.
As the
/var/run
is mounted as a tmpfs, its content is deleted on restart, symlink to the Docker socket included. To ensure the Docker socket exists after restart, Docker Desktop sets up a
launchd
startup task that creates the symlink by running
ln -s -f /Users/<user>/.docker/run/docker.sock /var/run/docker.sock
. This ensures the you aren't prompted on each startup to create the symlink. If you don't enable this option at installation, the symlink and the startup task is not created and you may have to explicitly set the
DOCKER_HOST
environment variable to
/Users/<user>/.docker/run/docker.sock
in the clients it is using. The Docker CLI relies on the current context to retrieve the socket path, the current context is set to
desktop-linux
on Docker Desktop startup.
For versions prior to 4.18, installing symlinks in
/usr/local/bin
is a privileged configuration Docker Desktop performs on the first startup. Docker Desktop checks if symlinks exists and takes the following actions:
-
Creates the symlinks without the admin prompt if
/usr/local/binis writable by unprivileged users. -
Triggers an admin prompt for you to authorize the creation of symlinks in
/usr/local/bin. If you authorizes this, symlinks to Docker binaries are created in/usr/local/bin. If you reject the prompt, are not willing to run configurations requiring elevated privileges, or don't have admin rights on your machine, Docker Desktop creates the symlinks in~/.docker/binand edits your shell profile to ensure this location is in your PATH. This requires all open shells to be reloaded. The rejection is recorded for future runs to avoid prompting you again. For any failure to ensure binaries are on your PATH, you may need to manually add to their PATH the/Applications/Docker.app/Contents/Resources/binor use the full path to Docker binaries.
A particular case is the installation of the
/var/run/docker.sock
symlink. Creating this symlink ensures various Docker clients relying on the default Docker socket path to work without additional changes. As the
/var/run
is mounted as a tmpfs, its content is deleted on restart, symlink to Docker socket included.
To ensure the Docker socket exists after restart, Docker Desktop sets up a
launchd
startup task that creates the symlink by running
ln -s -f /Users/<user>/.docker/run/docker.sock /var/run/docker.sock
. This ensures that you are not prompted on each startup to create the symlink. If you reject the prompt, the symlink and the startup task is not created and you may have to explicitly set the
DOCKER_HOST
to
/Users/<user>/.docker/run/docker.sock
in the clients it is using. The Docker CLI relies on the current context to retrieve the socket path, the current context is set to
desktop-linux
on Docker Desktop startup.