java class doesn't resolve IP on Alpine Docker container

When I run this code below inside container Docker running Java JDK 8 on Alpine Linux

import java.util.*;

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());
    . . . 

I get the error:

  • Failed to pull Docker image Beanstalk
  • Unknown filesystem type on /dev/mapper/docker-202
  • How do I make a standalone application out of a Docker container?
  • Play Framework - Passing Application Arguments via Docker Container
  • nginx in docker how to disable http redirects to https
  • subdomain is created via domain regitrar or web server?
  •   Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
      Exception in thread "main" mysql: unknown error
        at Method)
        at SomaDBTest.main(

    Any Ideas ?

    By the way, I can run the ping mysql and nslookup command successfully.

    # ping mysql 
    PING mysql ( 56 data bytes
    64 bytes from seq=0 ttl=64 time=0.185 ms
    64 bytes from seq=1 ttl=64 time=0.283 ms
    64 bytes from seq=2 ttl=64 time=0.424 ms
    # nslookup mysql
    Server:    (null)
    Address 1: ::1 localhost
    Address 2: localhost
    Name:      mysql
    Address 1: mysql

    My Dockerfile is very simple:

    FROM frolvlad/alpine-oraclejdk8
    ADD bin /

    The files and SomaDBTest.class is in bin directory.

    To run the container you do :

    docker build -t testInetAddress .
    docker run -i -t testInetAddress java SomaDBTest

  • Can't make nginx and php-fpm dockers communicate
  • Handling database schema creation and migrations when launching multiple instances of a containerized microservice
  • docker-compose down - network is external, skipping
  • Wildfly inside docker with externalized configuration
  • docker compose, vagrant and insecure Repository
  • can't pull docker images from nexus proxy
  • One Solution collect form web for “ java class doesn't resolve IP on Alpine Docker container”

    You can put the command bellow on your Dockerfile to solve this problem

    RUN echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf 
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.