0

I'm running on the same host a tomcat container where I've deployed a web application and an oracle DB container. The settings I'm using the following settings to connect from the web app to the oracle DB container:

spring.datasource.url: jdbc:oracle:thin:@<IP of the host>:1521:xe 
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=com.mysql.jdbc.Driver

As I'm exposing the port 1521 to the host, I was expecting to be able to connect to the Oracle DB with no issues, furthermore, I can connect from my laptop to the Oracle DB using DbVisualizer using the settings described above. I've also got into the tomcat container and pinged the host with success.

I know I could link both containers when running the "docker run" command but I was wondering if it could work this way too.

Any ideas? Thanks!

1 Answer 1

1

A simple way to do this is using docker-compose:

docker-compose.yml

version:'3'
services:
  app:
    // if you got a custom dockerfile
    build: . 
    links:
      - db
  db:
    image: oracledb

The db host into app will "db": spring.datasource.url: jdbc:oracle:thin:db:1521:xe

To run bought contanier at the same time is: docker-compose up --build

I hope you find it useful.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks German, I know about docker compose but I thought my setup should work as well.
Just as a side note, this is not really a docker-compose specific thing. By default, all containers connected to the same docker network create network can resolve their ip addresses by the --name of the container you want to connect to. There is a way to add an alias as well using --net-alias. Under the hood, docker-compose uses the net alias feature to set an alias that matches the service name from the docker-compose file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.