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)
Forgetting the password is a headache. What shoul...
Thanks to the development of the Internet, we can...
Preface When operating and managing Linux servers...
Preface This article mainly introduces the releva...
After reading some articles, I finally figured ou...
When looking at High Performance MySQL Version 3 ...
Recent projects involve the creation of a lot of ...
Table of contents What is front-end routing? How ...
In this article, I will show you how to develop a...
As a tester, you may often need to install some s...
As the most commonly used layout element, DIV play...
The specific code is as follows: <style> #t...
illustrate: Today, when continuing the last offic...
I had always wanted to learn Kubernetes because i...
Awk is a powerful tool that can perform some task...