title: Docker-compose with spring-boot and MySQL works incorrect
body: <p>I'm trying to build and run docker-compose with spring-boot and MySQL. At the same time I want application.properties to be defined not in project but in docker-compose. When I build and run docker-compose file, the container works but when I try to go to the server with <code>http://localhost:8080/investor/</code>, this site can't be reached. I will be grateful for any help to find where the problem is.
  My structure of files:
  <a href="https://i.stack.imgur.com/s2Vrd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s2Vrd.png" alt="enter image description here" /></a></p>
  <p>My docker-compose.yml:</p>
  <pre><code>version: &quot;3&quot;
  services:
    mysqldb:
      image: mysql
      restart: unless-stopped
      env_file: ./.env
      environment:
        - MYSQL_ROOT_PASSWORD=$MYSQLDB_ROOT_PASSWORD
        - MYSQL_DATABASE=$MYSQLDB_DATABASE
      ports:
        - &quot;${MYSQLDB_LOCAL_PORT}:${MYSQLDB_DOCKER_PORT}&quot;
      volumes:
        - db:/var/lib/mysql
    app:
      depends_on:
        - mysqldb
      build: .
      restart: on-failure
      env_file: ./.env
      ports:
        - &quot;${SPRING_LOCAL_PORT}:${SPRING_DOCKER_PORT}&quot;
      environment:
        SPRING_APPLICATION_JSON: '{
          &quot;spring.datasource.url&quot;  : &quot;jdbc:mysql://mysqldb:$MYSQLDB_DOCKER_PORT/$MYSQLDB_DATABASE?useSSL=false&quot;,
          &quot;spring.datasource.username&quot; : &quot;$MYSQLDB_USER&quot;,
          &quot;spring.datasource.password&quot; : &quot;$MYSQLDB_ROOT_PASSWORD&quot;,
          &quot;spring.jpa.properties.hibernate.dialect&quot; : &quot;org.hibernate.dialect.MySQL5InnoDBDialect&quot;,
          &quot;spring.jpa.hibernate.ddl-auto&quot; : &quot;update&quot;
        }'
      volumes:
        - .m2:/root/.m2
      stdin_open: true
      tty: true
  volumes:
    db:
  </code></pre>
  <p>My .env:</p>
  <pre><code>MYSQLDB_USER=root
  MYSQLDB_ROOT_PASSWORD=123456
  MYSQLDB_DATABASE=investor
  MYSQLDB_LOCAL_PORT=3307
  MYSQLDB_DOCKER_PORT=3306
  SPRING_LOCAL_PORT=6868
  SPRING_DOCKER_PORT=8080
  </code></pre>
  <p>My Dockerfile:</p>
  <pre><code>FROM maven:3.8.6-openjdk-18
  WORKDIR /investor-app
  COPY . .
  RUN mvn clean install
  CMD mvn spring-boot:run
  </code></pre>
  <p>My pom.xml:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.7.3&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.ensei&lt;/groupId&gt;
      &lt;artifactId&gt;InvestmentCalculator&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;InvestmentCalculator&lt;/name&gt;
      &lt;description&gt;Tool for calculation of benefits from investment projects&lt;/description&gt;
      &lt;properties&gt;
          &lt;java.version&gt;17&lt;/java.version&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.h2database&lt;/groupId&gt;
              &lt;artifactId&gt;h2&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/org.jsoup/jsoup --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jsoup&lt;/groupId&gt;
              &lt;artifactId&gt;jsoup&lt;/artifactId&gt;
              &lt;version&gt;1.15.3&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  <p>My Controller.class:</p>
  <pre><code>package com.ensei.InvestmentCalculator.controller;
  
  import com.ensei.InvestmentCalculator.model.InvestmentManager;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.*;
  
  import java.io.IOException;
  
  @Controller
  @RequestMapping(&quot;investor&quot;)
  public class MyController {
  
      @Autowired
      private InvestmentManager manager;
  
      @GetMapping
      public String menu(){
          return &quot;menu&quot;;
      }
  
      @GetMapping(&quot;/add&quot;)
      public String add(Model model){
          return &quot;add&quot;;
      }
  
      @PostMapping (&quot;/add/{name}&quot;)
      public String addDone(Model model, @RequestParam String name, String initialInvestment,
                            String annuity, String differentCashFlow, String period,
                            String customDiscountRate) throws IOException {
          try {
              manager.addInvestmentProject(name, initialInvestment, annuity, differentCashFlow, period, customDiscountRate);
          } catch (Exception e) {
              return &quot;exceptions/incorrectData&quot;;
          }
          model.addAttribute(&quot;name&quot;,name);
          return &quot;addDone&quot;;
      }
  
      @GetMapping(&quot;/read&quot;)
      public String read(Model model){
          model.addAttribute(&quot;projects&quot;,manager.readInvestmentProjects());
          return &quot;read&quot;;
      }
  
      @GetMapping(&quot;/update&quot;)
      public String update(Model model){
          return &quot;update&quot;;
      }
  
      @PostMapping (&quot;/update/{name}&quot;)
      public String updateDone(Model model, @RequestParam String name, String initialInvestment,
                            String annuity, String differentCashFlow, String period,
                            String customDiscountRate) throws IOException {
          try {
               manager.updateInvestmentProject(name,initialInvestment,annuity,differentCashFlow,period,customDiscountRate);
          } catch (Exception e){
              return &quot;exceptions/incorrectData&quot;;
          }
         model.addAttribute(&quot;name&quot;,name);
          return &quot;updateDone&quot;;
      }
  
      @GetMapping(&quot;/delete&quot;)
      public String delete(){
          return &quot;delete&quot;;
      }
  
      @PostMapping (&quot;/delete/{name}&quot;)
      public String deleteDone(Model model, @RequestParam String name){
          try {
              manager.deleteInvestmentProject(name);
          } catch (Exception e){
              return &quot;exceptions/incorrectProject&quot;;
          }
          model.addAttribute(&quot;name&quot;,name);
          return &quot;deleteDone&quot;;
      }
  
      @PostMapping(value = {&quot;/add&quot;,&quot;/update&quot;})
      public String absentName(){
          return &quot;exceptions/absentName&quot;;
      }
  }
  </code></pre>
  <p>My application.properties file is empty.</p>