This machine installs a Docker, the remote host installs a Docker, this article mainly explains how to use the local Docker client to access the remote host's Docker daemon
By default, the Docker daemon generates a socket (/var/run/docker.sock) file for local process communication without listening to any ports, so you can only use the Docker client locally or use the Docker API to do so.
If you want to operate a Docker host on another host, you need to have the Docker daemon listen to a port for remote communication.
Modify the Docker service startup configuration file, add an unused port number, and restart the Docker daemon.
# Vim/etc/default/docker
docker_opts= "-H 0.0.0.0:5555"
# service Docker restart
If you do not have this file, you should consider modifying the/etc/sysconfig/docker file.
Now that the Docker daemon is listening on port 5555, the Docker process can be accessed through that port on another host.
Example Description:
We can access another Docker-mounted machine from one of the Docker-mounted machines. In general, we use the Docker client of the current machine to access the server side of the current machine. The following shows how to access other Docker server ports.
First set of ip:192.168.12.3
Second set of ip:192.168.12.4
Demo with a second server with Docker installed. To differentiate, set the label differently.
To modify the daemon (Server) default startup configuration:
The default is:-H fd://, can be modified to:-H tcp://0.0.0.0:2375-h unix:///var/run/docker.sock-h fd://--label name=server_1
Multiple connection modes can be set.
TCP is a remote connection, UNIX is a local socket link, FD does not know.
The first Docker service to access the second machine:
Connect to server via http:
Curl Http://192.168.12.4:2375/info
Accesses the info interface of the server 192.168.12.4:2375 and returns information about the server.
Accessing the server through a Docker client:
Docker-h tcp://192.168.12.4:2375 Info
If it is the first machine to access the first machine Docker server, then use 127.0.0.1:2375.
As with the server side, the client also supports three kinds of connection methods, by default,-H Unix:///var/run/docker.sock:
-H Unix:///path/to/sock
Tcp://host:port
Fd://socketfd
The Docker client uses Docker info to access the local server by default. You can modify the environment variable Docker_host to change the default connection. command line input directly:
Export docker_host= "tcp://127.0.0.1:2375"
The 127.0.0.1:237 can be replaced with the actual server address.
If you want to restore the local connection, leave the docker_host empty:
export docker_host= ""