title: Dockerized Spring Boot app can't connect to database container
body: <p>I have a basic Spring Boot application with gradle and Hibernate which makes calls to an Oracle database, the database being in a docker container.</p>
  
  <p>I created a Docker image of the spring boot application with the plugin "com.google.cloud.tools.jib" and using the following command:</p>
  
  <pre><code>./gradlew jibDockerBuild --image=app1
  </code></pre>
  
  <p>I already created a user-defined network ( let's call it <strong>my_network</strong> ) and I've attached the database container to the above mentioned network.</p>
  
  <p>I have a docker-file in which even though I specify the image as an service and use <strong>my_network</strong> when I run I hit the "docker-compose up" command in CMD I receive the following exception:</p>
  
  <pre><code>java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
  </code></pre>
  
  <p>The docker-compose file is the following:</p>
  
  <pre><code>version: '3.7'
  
  networks:
      my_network:
          external: 
              name: my_network
  
  services:
     app1:
     image: "app1"
     ports:
       - "9090:9090"
     environment: 
       SPRING_DATASOURCE_URL: "jdbc:oracle:thin:@localhost:32769/ORCLPDB1.localdomain"
       SPRING_DATASOURCE_USERNAME: username
       SPRING_DATASOURCE_PASSWORD: password 
     networks:
       - my_network
  </code></pre>
  
  <p>Tried solutions but with no result:</p>
  
  <ol>
  <li>Specified database as service so basically let it be created the first time I hit "docker-compose up" and in service app1 specified the tag depends_on but the database container created would be in a health:starting state long after the app1 had been started and crashed</li>
  <li>Let the network be created inside from the docker-compose file but same behavior as in the asked question</li>
  <li>Replaced localhost with <strong>host.docker.internal</strong> in the database url but it said is was an unknown host</li>
  </ol>