如何使用docker-compose将docker oracle container ip放入java应用程序?

时间:2017-09-07 14:35:37

标签: docker docker-compose

以下代码iam在docker-compose中使用:

integration_test:

  image: service:1.0.0

  volumes:
    - .:/service

  links:
   - oracle_container
  # used volumes_from as workaround to wait until the following containers to start

  volumes_from:
   - oracle_container

  container_name: integration_test

  tty: true

  environment:
    USER: go

  command: ["mvn clean install -DskipTests"]

oracle_container:

  image: inmage_name:1.0.0

  container_name: oracle_container

  ports:
    - "49161:1521"

我想让两个容器谈论应用程序 - > oracle

两个容器都在同一台机器上运行,我使用下面的jdbc字符串通过应用程序连接oracle,

JDBC:预言:瘦:@localhost:49161 / XE

但我无法连接oracle及其抛出的SQLRecoverable异常。

根据我的理解,这属于Docker Networking,我使用链接连接两个容器。但是这个问题是连接字符串,更具体地说是oracle容器的ip。

有人可以帮忙解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

您需要使用

private static string NextInString(List<string> names, string userName)
{       
    int index = names.IndexOf(userName);

    if(names.Count - 1 == index || index == -1)
    {
        return "No result";
    }
    else
    {
        return names[index + 1];
    }
}

在docker-compose中,每个容器都可以到达其他容器名称的服务名称。您不应该使用主机端口而只使用容器端口

相关问题