CentOS7 docker open tcp port and remote connectivity for client

#docker Version: 18.09.0, the best guarantee of the same client port and server port

[root@Centos7 ~]# dockerd-ce -v
Docker version 18.09.0, build 4d60db4

 

Overview Network 

Server: 192.168.100.7: 2375   

Client: 192.168.100.8

#docker default connection provides only local unix, sock file, so docker able to listen to tcp ports also need to do some configuration.

1. Go docker startup file, define the parameters executed at startup.

#dockerd -H parameter specifies docker application listens way. Of course, socket file location, port 2375 can change yourself, socket file location change, then also need to adjust some parameters when using the docker command, will explain the connection.

[root@server system]# cat /lib/systemd/system/docker.service   |grep "ExecStart" --color
ExecStart=/usr/bin/dockerd  -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375

 

2. Adjust the configuration and reboot docker services, and observe whether the port is listening

[root@server ~]# systemctl  restart docker
[root@server ~]# ss -lt  |grep 2375
LISTEN     0      128       :::2375                    :::*     

3.telnet test server port 2375

[root@client ~]# telnet 192.168.100.7  2375
Trying 192.168.100.7...
Connected to 192.168.100.7.
Escape character is '^]'.
^]
telnet> quit

# If telnet fails, there is a limit may be server-side firewall, add a rule in the bottom of the connection test.

[root@server ~]# iptables -I INPUT -ptcp --dport 2375 -j ACCEPT

 

 

# In the client-side connection server and execute the command

1.tcp connection

# When you use docker connection, you may experience the following problems: first path segment in URL can not contain colon

#ps for the command to execute server-side

[root@client ~]# docker -H 192.168.100.7:2375  ps 
parse 192.168.100.7:2375: first path segment in URL cannot contain colon

# The above command changes the following command.

[root@client ~]# docker -H tcp://192.168.100.7:2375  ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

 

2.unix socket file connection.

# Similarly, we must specify the location of the socket file if you change the location of the sock file, the file is connected through the socket of the machine.

[root@server ~]# docker -H unix:///var/run/docker.sock  ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Guess you like

Origin www.cnblogs.com/kcxg/p/12202104.html