Spring boot app running inside docker container unable to connect to Oracle DB on network

I am new to docker, I am trying to run spring boot app (microservice) in docker container, app is trying to access a oracle db on network not running inside docker container

public DataSource oracleDataSource() throws SQLException {
            final SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
            dataSource.setDriver(new OracleDriver());
            dataSource.setUrl("jdbc:oracle:thin:@kdb-us-engdba11:1521:ora11gr2");
            dataSource.setUsername("xxx");
            dataSource.setPassword("xxx");

            return dataSource;
        }

It works fine when same code is run from eclipse but when running inside docker container it throws java.net.UnknownHostException: kdb-us-engdba11: unknown error. I tried

docker run --add-host=kdb-us-engdba11.int.kronos.com:10.48.151.183..." 
and  "docker run --net=host .....

both option does not seems like helping, how to access network resource from docker container. I am running the code on mac with Boot2Docker for OSX.

Thanks, Rahul

Hi Rahul,

You have used fqdn for --add-host where as your code is using a short name. Possibly this is the problem. You have two options here.

  • Either run the container using short name
    docker run --add-host=kdb-us-engdba11:10.48.15 1.183 ....

  • Or edit the code and use fqdn in the connection url dataSource.setUrl.

Regards
Ranjan