Get the local public IP address through the container. You can use the local IP address to register multiple services. Changing the command to ping can get different server information. public static String getIfconfigIP() { BufferedReader in = null; String outline = ""; // timeOut window is in ms and in linux is in s Runtime r = Runtime.getRuntime(); // The ping command to be executed, this command is a Windows format command String pingCommand = " curl ifconfig.me "; // Windows system String os = System.getProperty("os.name").toLowerCase(); if (os.indexOf("linux") >= 0) { pingCommand = " curl ifconfig.me "; } if (os.indexOf("mac") >= 0) { pingCommand = " curl ifconfig.me "; } try { // Execute the command and get the output System.out.println(pingCommand); Process p = r.exec(pingCommand); if (p == null) { return "cmd failed"; } in = new BufferedReader(new InputStreamReader(p.getInputStream())); // Check the output line by line, and calculate similar occurrences = 23ms // Number of times TTL=62 is shown int connectedCount = 0; String line = null; while ((line = in.readLine()) != null) { outline += line; } return outline; } catch (Exception ex) { ex.printStackTrace(); // If an exception occurs, return false return outline; } finally { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } The IP in docker is fake. How to get the IP address of the host machine in the program running in docker? Here are some tips for me p = require('child_process') .spawnSync('curl', ['ifconfig.io']) .stdout .toString() .trim() Additional knowledge: Docker network problem. The external IP address of the host machine cannot be pinged in the Docker container, but the external IP address of other machines can be pinged. Problem Description Machine A and machine B each have their own internal IP and external IP, for example: A-IP-internal, A-IP-external B-IP-inside, B-IP-outside, machine A has a domain name www.xxx.com Install the Jenkins Docker container on machine A, start it, and enter the container
Then ping the intranet IP of host A in the container, and it works.
in addition: 1. From the host machine A outside the docker container, ping A-IP-outside (202.106...) is successful. 2. Install the Jenkins container on machine B, and ping A-IP-external (202.106...) from within the container. 2. Install the Jenkins container on machine B. Pinging B-IP-external (202.106…) from within the container is unsuccessful. Looking for various network problems, deleting containers, images, and reinstalling docker all do not work. In summary: How to ping the host's public IP in the docker container? I need to ping www.xxx.com in the container of machine A, which will be resolved to the intranet address of machine A. Because the intranet address of machine A can be pinged from within the container. New modified docker-compose file
After rebuilding the docker container, enter the docker container
The above article about how to get the public IP address of a docker container by running it directly through ping is all I have to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Web page comments cause text overflow in IE
>>: MySQL 8.0.22 decompression version installation tutorial (for beginners only)
Ansible is a new automated operation and maintena...
background Getting the slow query log from mysql....
Deploy redis in docker First install Docker in Li...
I have been playing around with charts for a whil...
Because frameset and body are on the same level, y...
This article shares the specific code of JavaScri...
Use the rpm installation package to install mysql...
1. What is the cardinality? Cardinality refers to...
in conclusion % of width: defines the percentage ...
1. View the types of fields in the table describe...
This article shares the specific code for JavaScr...
question: <input type="hidden" name=...
This article describes how to install lamp-php7.0...
What is Redis Cluster Redis cluster is a distribu...
What is routing? Routing refers to the activity o...