Q: Communications link failure , docker-compose i have a problem with docker compose when i try to run docker-compose every time i get the following error i tried many solutions but nothing helps. Please help.
I will add that I created the docker image using Cloud Native Buildpacks. I used the command:
mvn spring-boot: build-image -Dspring-boot.build-image.imageName = jakuczczubak/infrastock
and then uploaded the image to dockerhub
dockerhub: dockerhub
github: github
docker-compose.yml
    services:

  mysql:
    image: mysql:5.7
    container_name: test-mysql-docker
    environment:
      - MYSQL_ROOT_PASSWORD=mysqlpw
      - MYSQL_USER=infrastock
      - MYSQL_DATABASE=infrastock
      - MYSQL_PASSWORD=infrastock123
    ports:
      - 33067:3306


  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
    depends_on:
      - mysql

  api:
    image: czubakjakub/infrastock:v1.0.0
    environment:
      - SPRING_DATASOURCE_URL=jdbc:mysql://root:mysqlpw@test-mysql-docker:3306/infrastock?useSSL=false
      - SPRING_JPA_HIBERNATE_DDL-AUTO=update
    ports:
      - 9090:9090
    depends_on:
      - mysql

application.properties
server.port=9090

spring.datasource.url=jdbc:mysql://root:mysqlpw@host.docker.internal:33067/infrastock
spring.jpa.hibernate.ddl-auto=update

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect

error:
- Network docker-compose_default      Created                                                                     2.6s
 - Container test-mysql-docker         Created                                                                     0.6s
 - Container docker-compose-api-1      Created                                                                     0.6s
 - Container docker-compose-adminer-1  Created                                                                     0.5s
Attaching to docker-compose-adminer-1, docker-compose-api-1, test-mysql-docker
test-mysql-docker         | 2022-06-22 18:55:25+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.38-1debian10 started.
test-mysql-docker         | 2022-06-22 18:55:25+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
test-mysql-docker         | 2022-06-22 18:55:25+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.38-1debian10 started.
test-mysql-docker         | 2022-06-22 18:55:25+00:00 [Note] [Entrypoint]: Initializing database files
test-mysql-docker         | 2022-06-22T18:55:25.410856Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
test-mysql-docker         | 2022-06-22T18:55:27.139862Z 0 [Warning] InnoDB: New log files created, LSN=45790
test-mysql-docker         | 2022-06-22T18:55:27.489120Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
test-mysql-docker         | 2022-06-22T18:55:27.590997Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e1816692-f25c-11ec-951c-0242ac130002.
test-mysql-docker         | 2022-06-22T18:55:27.604367Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
test-mysql-docker         | 2022-06-22T18:55:28.037561Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
test-mysql-docker         | 2022-06-22T18:55:28.037615Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
test-mysql-docker         | 2022-06-22T18:55:28.038212Z 0 [Warning] CA certificate ca.pem is self signed.
test-mysql-docker         | 2022-06-22T18:55:28.080678Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
docker-compose-adminer-1  | [Wed Jun 22 18:55:29 2022] PHP 7.4.30 Development Server (http://[::]:8080) started
docker-compose-api-1      | Setting Active Processor Count to 8
docker-compose-api-1      | Calculating JVM memory based on 7046808K available memory
docker-compose-api-1      | `For more information on this calculation, see https://paketo.io/docs/reference/java-reference/#memory-calculator
docker-compose-api-1      | Calculated JVM Memory Configuration: -XX:MaxDirectMemorySize=10M -Xmx6417274K -XX:MaxMetaspaceSize=117533K -XX:ReservedCodeCacheSize=240M -Xss1M (Total Memory: 7046808K, Thread Count: 250, Loaded Class Count: 18337, Headroom: 0%)
docker-compose-api-1      | Enabling Java Native Memory Tracking
docker-compose-api-1      | Adding 127 container CA certificates to JVM truststore
docker-compose-api-1      | Spring Cloud Bindings Enabled
docker-compose-api-1      | Picked up JAVA_TOOL_OPTIONS: -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -XX:+ExitOnOutOfMemoryError -XX:ActiveProcessorCount=8 -XX:MaxDirectMemorySize=10M -Xmx6417274K -XX:MaxMetaspaceSize=117533K -XX:ReservedCodeCacheSize=240M -Xss1M -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+PrintNMTStatistics -Dorg.springframework.cloud.bindings.boot.enable=true
docker-compose-api-1      |
docker-compose-api-1      |   .   ____          _            __ _ _
docker-compose-api-1      |  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
docker-compose-api-1      | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
docker-compose-api-1      |  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
docker-compose-api-1      |   '  |____| .__|_| |_|_| |_\__, | / / / /
docker-compose-api-1      |  =========|_|==============|___/=/_/_/_/
docker-compose-api-1      |  :: Spring Boot ::                (v2.6.3)
docker-compose-api-1      |
docker-compose-api-1      | 2022-06-22 18:55:31.261  INFO 1 --- [           main] c.e.infrastock.InfraStockApplication     : Starting InfraStockApplication v0.0.1-SNAPSHOT using Java 11.0.15.1 on a109f4fe4312 with PID 1 (/workspace/BOOT-INF/classes started by cnb in /workspace)
docker-compose-api-1      | 2022-06-22 18:55:31.270  INFO 1 --- [           main] c.e.infrastock.InfraStockApplication     : No active profile set, falling back to default profiles: default
docker-compose-api-1      | 2022-06-22 18:55:32.883  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
docker-compose-api-1      | 2022-06-22 18:55:33.021  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 124 ms. Found 4 JPA repository interfaces.
docker-compose-api-1      | 2022-06-22 18:55:34.554  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9090 (http)
docker-compose-api-1      | 2022-06-22 18:55:34.583  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
docker-compose-api-1      | 2022-06-22 18:55:34.584  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.56]
docker-compose-api-1      | 2022-06-22 18:55:34.777  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
docker-compose-api-1      | 2022-06-22 18:55:34.777  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3377 ms
docker-compose-api-1      | Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
docker-compose-api-1      | 2022-06-22 18:55:35.258  INFO 1 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
docker-compose-api-1      | 2022-06-22 18:55:35.367  INFO 1 --- [           main] org.hibernate.Version
   : HHH000412: Hibernate ORM core version 5.6.4.Final
docker-compose-api-1      | 2022-06-22 18:55:35.583  INFO 1 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
docker-compose-api-1      | 2022-06-22 18:55:35.753  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
docker-compose-api-1      | 2022-06-22 18:55:35.772  WARN 1 --- [           main] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
docker-compose-api-1      | 2022-06-22 18:55:36.976 ERROR 1 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.
docker-compose-api-1      |
docker-compose-api-1      | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
docker-compose-api-1      |
docker-compose-api-1      | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
docker-compose-api-1      |     at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.28.jar:8.0.28]
docker-compose-api-1      |     at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.28.jar:8.0.28]
docker-compose-api-1      |     at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:829) ~[mysql-connector-java-8.0.28.jar:8.0.28]
docker-compose-api-1      |     at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:449) ~[mysql-connector-java-8.0.28.jar:8.0.28]
docker-compose-api-1      |     at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:242) ~[mysql-connector-java-8.0.28.jar:8.0.28]
docker-compose-api-1      |     at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) ~[mysql-connector-java-8.0.28.jar:8.0.28]
docker-compose-api-1      |     at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1      |     at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1      |     at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1      |     at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1      |     at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1      |     at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1      |     at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar:na]
docker-compose-api-1      |     at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:181) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:175) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:173) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:127) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1460) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1494) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final]
docker-compose-api-1      |     at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.15.jar:5.3.15]
docker-compose-api-1      |     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.15.jar:5.3.15]

Full stack trace: https://pastebin.com/mLPfHNbJ
Full docker-compose.yml logslogs
