The app connects just fine when run without docker using mvn spring-boot:run. When run using mvn docker:remove docker:stop clean package docker:build docker:start the following error is being thrown
Error:
    [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.DatabaseException: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
application.yaml
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/db?user=root&createDatabaseIfNotExist=true
    username: root
    password: new_password
    driver-class-name: com.mysql.cj.jdbc.Driver
    hikari:
      connection-timeout: 20000
      idle-timeout: 10000
  liquibase:
    enabled: true
pom.xml
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.33.0</version>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <id>docker-build</id>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>prepare-database</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>remove-database</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <images>
                        <image>
                            <name>mysql</name>
                            <alias>database</alias>
                            <run>
                                <log>
                                    <prefix>mysql > </prefix>
                                    <enabled>true</enabled>
                                    <color>green</color>
                                </log>
                                <env>
                                    <MYSQL_ROOT_PASSWORD>${db.password}</MYSQL_ROOT_PASSWORD>
                                    <MYSQL_DATABASE>${db.name}</MYSQL_DATABASE>
                                    <MYSQL_PASSWORD>${db.password}</MYSQL_PASSWORD>
                                </env>
                                <ports>
                                    <port>3306:3306</port>
                                </ports>
                                <wait>
                                    <log>(?s)ready for connections</log>
                                    <time>30000</time>
                                </wait>
                            </run>
                        </image>
                        <image>
                            <alias>service</alias>
                            <name>service</name>
                            <build>
                                <from>java:8-jre</from>
                                <cmd>
                                    <shell>java -jar /maven/mysql-producer-consumer-1.0-SNAPSHOT.jar</shell>
                                </cmd>
                                <assembly>
                                    <descriptorRef>artifact-with-dependencies</descriptorRef>
                                </assembly>
                            </build>
                            <run>
                                <log>
                                    <prefix>service > </prefix>
                                    <enabled>true</enabled>
                                    <color>black</color>
                                </log>
                                <wait>
                                    <shutdown>500</shutdown>
                                    <time>20000</time>
                                </wait>
                                <dependsOn>
                                    <container>mysql</container>
                                </dependsOn>
                            </run>
                        </image>
                    </images>
                </configuration>
            </plugin>
Changing datasource url to following values didn't work:
jdbc:mysql://mysql/db?user=root&createDatabaseIfNotExist=truejdbc:mysql://database/db?user=root&createDatabaseIfNotExist=truejdbc:mysql://localhost/db?user=root&createDatabaseIfNotExist=true