Skip to content
Advertisement

How can i connect to the oracle database between docker containers?

I have two containers that is created from docker-compose, one has api with springboot and the other oracle database, however it does’n connect the api to the database and I already ran out options, I tried configure the connection in the aplication.properties and also docker-compose.yml

This is docker-compose.yml

JavaScript

Dockerfile

JavaScript

aplication.properties

JavaScript

(The connection was commented because in the docker-compose it’s configured)

I appreciate the help (My apologies for my english)

————– UPDATE ————–

Connection test

JavaScript

Advertisement

Answer

TLDR

Change the port to 1521 in your connection string.

Extended version

Your services and networking are configure properly. Both containers are in the same docker network, which allows them to communicate with each other.

Also, contrary to some of the comments, all 3 ways of calling the containers are correct:

  • db
  • db-host
  • oracle_db.

This can be easily verified using a simplified docker-compose.yml, just to test the connectivity:

JavaScript

If you try to resolve the names – they all point to the same container:

JavaScript

In fact, the problem seems to be with your connection string:

JavaScript

port 49161 is the host port, while your connecting to the container (db). In this case you should be using the 1521 port, which the server inside the container is bound to.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement