Home>

I just begin to study Dokk, and everything connected with him, so there was a problem. I have my own service on the Spring Boot that must be condensed to MySQL. On the host everything works fine. I'm trying to transfer it all in Docker-Compose, but for some reason, he does not see the database.

Here is my donkerfile service:

from adoptopenjdk /openjdk11: ubi
VOLUME /TMP.
Add ./hotel.jar app.jar
Expose 8080.
CMD Sleep 30 &
&
 java -jar app.jar

Here is a function of service:

Spring.DataSource.url= JDBC: MySQL: //Localhost: 3306 /Senla_TraineShip? AllowPublicKeyretrieval= True &
Usessl= False &
ServerTimeZone= UTC.
spring.datasource.username= root.
Spring.Datasource.password= TestTest
Spring.liquibase.Change-log= Classpath: Liquibase /db.changelog.master.xml
Spring.liquibase.url= JDBC: MySQL: //Localhost: 3306 /Senla_Traineeship? AllowPublicKeyretrieval= True &
Usessl= False &
ServerTimeZone= UTC &
Createdatabseifnotexist= True.
Spring.liquibase.user= root
Spring.liquibase.password= TestTest

It looks like my docker-compose.xml

Version: '2'
Services:
  MySQL:
    Image: MySQL: 5.7
    Restart: Always
    Environment:
      MySQL_ROOT_PASSWORD: TestTest
    Ports:
      -3306: 3306
    Expose:
      # Opens Port 3306 on the Container
      -3306.
  Hotel:
    CONTAINER_NAME: HOTEL.
    Build: ./hotel.
    Ports:
      -8080: 8080
    Environment:
      Mysql_Server: MySQL: 3306
    DEPENDS_ON:
      -MySQL

And here is the error that my service gives me:

If it matters, I have Win 8. What am I doing wrong? It seems to be all by manuals.

  • Answer # 1

    After several days of research, I managed to solve this problem. DockerFile has not changed. Property service had to change. Now they look like this:

    Spring.DataSource.url= JDBC: MySQL: //MySQL: 3306 /Senla_TraineEship? AllowPublicKeyretrieval= True &
    Usessl= False &
    ServerTimeZone= UTC.
    spring.datasource.username= root.
    Spring.Datasource.password= TestTest
    Spring.liquibase.Change-log= Classpath: Liquibase /db.changelog.master.xml
    Spring.liquibase.url= JDBC: MySQL: //MySQL: 3306 /Senla_TraineShip? AllowPublicKeyretrieval= True &
    Usessl= False &
    ServerTimeZone= UTC &
    Createdatabseifnotexist= True.
    Spring.liquibase.user= root
    Spring.liquibase.password= TestTest
    

    Docker Compose now looks like this:

    Version: '3'
    Services:
      MySQL:
        Container_Name: MySQL.
        Image: MySQL
        Restart: Always
        Environment:
          MySQL_Database: Senla_TraineShip.
          Mysql_root_host: '%'
          MySQL_ROOT_PASSWORD: TestTest
        Ports:
          -"6033: 3306"
        Volumes:
          -./sql:/dockeredrypoint-initdb.d.
    Hotel:
        CONTAINER_NAME: HOTEL.
        Build: ./hotel.
        Expose:
          -"8080"
        Ports:
          -8080: 8080
        Environment:
          Wait_Hosts: MySQL: 3306
        DEPENDS_ON:
          -MySQL
    

    As I understand it, the problem was that the service turned to the database through Lockalchost, and it was necessary to contact the name of the container's host with the database (I could be wrong). Therefore, I was clearly indicated by the names for the host.

  • Answer # 2

    After several days of research, I managed to solve this problem. DockerFile has not changed. Property service had to change. Now they look like this:

    Spring.DataSource.url= JDBC: MySQL: //MySQL: 3306 /Senla_TraineEship? AllowPublicKeyretrieval= True &
    Usessl= False &
    ServerTimeZone= UTC.
    spring.datasource.username= root.
    Spring.Datasource.password= TestTest
    Spring.liquibase.Change-log= Classpath: Liquibase /db.changelog.master.xml
    Spring.liquibase.url= JDBC: MySQL: //MySQL: 3306 /Senla_TraineShip? AllowPublicKeyretrieval= True &
    Usessl= False &
    ServerTimeZone= UTC &
    Createdatabseifnotexist= True.
    Spring.liquibase.user= root
    Spring.liquibase.password= TestTest
    

    Docker Compose now looks like this:

    Version: '3'
    Services:
      MySQL:
        Container_Name: MySQL.
        Image: MySQL
        Restart: Always
        Environment:
          MySQL_Database: Senla_TraineShip.
          Mysql_root_host: '%'
          MySQL_ROOT_PASSWORD: TestTest
        Ports:
          -"6033: 3306"
        Volumes:
          -./sql:/dockeredrypoint-initdb.d.
    Hotel:
        CONTAINER_NAME: HOTEL.
        Build: ./hotel.
        Expose:
          -"8080"
        Ports:
          -8080: 8080
        Environment:
          Wait_Hosts: MySQL: 3306
        DEPENDS_ON:
          -MySQL
    

    As I understand it, the problem was that the service turned to the database through Lockalchost, and it was necessary to contact the name of the container's host with the database (I could be wrong). Therefore, I was clearly indicated by the names for the host.