Is there a specific reason you are using docker-machine
instead of the Docker Desktop
app? With the latter one, many things like spinning up a virtual machine, setting config and mounting volumes happen in the background.
For details check https://www.docker.com/products/docker-desktop (make sure to uninstall the tooling you currently use)
Answering your specific question on docker-machine env
:
The docker
CLI tool interacts with the daemon process via unix or tcp sockets. The default setting of the cli is to look for a unix socket at the path you mentioned (unix:///var/run/docker.sock
).
Because the docker daemon cannot run natively on MacOS, you need to use some linux virtual machine to be able to use docker on a Mac. Docker-machine is the old way of doing this, which is basically a tool that spins up a new virtual machine that gets some (rather) random ip address. If your MacOS-local CLI now wants to connect to this machine, it needs to use the tcp socket on this specific IP address. The docker-machine env
command basically creates some environment variables for your docker CLI to overwrite the default setting of unix:///var/run/docker.sock
. Besides the TCP socket URL, it also configures some certificates to be used to authenticate against the docker socket of the VM. All those env variables configure the docker CLI tool.
The eval
command automatically applies those environment varibale exports to the currently active shell. Those values are ephemeral and do not persist over restarts or when opening up a new shell.
You could possibly put those values into your shell configuration so that they are applied automatically (e.g. in .bashrc
or .zshrc
). But as the IP address might not be stable, you may run into issues where your shell points to an old configuration. That's why you might execute this command each and every time to have the current setup.
For details on docker-machine env
see the docs at https://docs.docker.com/machine/reference/env/