What are the possible formats of the DOCKER_HOST URLs?

…衆ロ難τιáo~ 提交于 2021-01-29 17:48:28

问题


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 --tls flag 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 if DOCKER_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 the tcp://, 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 the ssh command to remotely login the remote server. The docker command should be available there in the default PATH. There is runs docker remotely, 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!