当我在Alpine Linux上运行Java JDK 8的容器Docker中运行此代码时
import java.io.*;
import java.util.*;
import java.net.*;
public class SomaDBTest {
public static void main(String... args) throws Throwable {
InetAddress ip = InetAddress.getByName("mysql");
System.out.println("Begin - mysql IP Addr = " + ip.getHostAddress());
. . .
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
Exception in thread "main" java.net.UnknownHostException: mysql: unknown error
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
at java.net.InetAddress.getAllByName(InetAddress.java:1192)
at java.net.InetAddress.getAllByName(InetAddress.java:1126)
at java.net.InetAddress.getByName(InetAddress.java:1076)
at SomaDBTest.main(SomaDBTest.java:52)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗 ?
顺便说一句,我可以成功运行ping mysql 和 …