问题
Remote docker servers can be reached by the docker cli by settings the DOCKER_HOST environment variable.
Mostly, tcp://<hostname-or-ip>:<port> or sometimes ssh://<hostname-or-ip>:<port> is used.
Unfortunately, the docker documentation talks about everything, except the possible URL formats of this variable. What are they, how do they work?
回答1:
The parsing of the DOCKER_HOST variable happens in the parseDockerDaemonHost function in the opts/hosts.go source fragment of the docker-cli.
The possible values are the following:
tcp://1.2.3.4:2375- it connects to the docker server at the TCP port 2375 of the remote system. Beside the IP, also the hostname can be used. Leaving out the port field, it defaults to 2375 in normal mode, or to 2376 if we use TLS encryption (docker client should be called with the--tlsflag for that).unix:///path/to/socket- it connects to a docker server listening on the local unix socket/path/to/socket. Unix sockets exist only on Linux (& co) systems. The path does not need to be an absolute one. The default value is/var/run/docker.sock(is connected ifDOCKER_HOST=unix://).npipe:///./pipe/docker_engine- named pipes are similar to the Unix sockets, but in the Windows world. It probably connects a local docker server running on a Windows. Note, docker on Windows runs on a Linux VM, over the HyperV virtualization engine of the Microsoft. And it is reached probably over the virtual network provided by the HyperV. Native Windows docker is not very widely used.fd://1.2.3.4:5678- Contrary its name, it behaves similarly to thetcp://, except that the port number does not defaults to 2375. Its exact working would probably need further digging in the docker-cli source.ssh://1.2.3.4:22- it calls thesshcommand to remotely login the remote server. Thedockercommand should be available there in the defaultPATH. There is runsdockerremotely, passing exactly the same arguments to it, with them we called it. Probably it can connect the docker server only on its default address (/var/run/docker.sock) on the remote side.
Any other URL formats are rejected with the Invalid bind address format error message.
The communication protocol is http(s), although I had some issues with it in proxied configurations.
来源:https://stackoverflow.com/questions/62757127/what-are-the-possible-formats-of-the-docker-host-urls