jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.47k stars 4.02k forks source link

Docker image app doesn't start #20263

Closed paris0120 closed 8 months ago

paris0120 commented 1 year ago
Overview of the issue

The docker image app of jhipster get stuck.

Motivation for or Use Case

Run app with dock compose

Reproduce the error

for example, gateway jdl:

application { config { baseName gateway, applicationType gateway, packageName com.spring.microservice.gateway.jhipster, authenticationType oauth2, prodDatabaseType mysql, reactive true, clientFramework angularX, skipClient false, serviceDiscoveryType eureka } entities * }

build image with ./mvnw package -Pprod verify jib:dockerBuild

then run the app.yml with "docker compose -f app.yml up"

I get docker-gateway-app-1 | 2022-11-10T19:08:33.203Z ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization. docker-gateway-app-1 | docker-gateway-app-1 | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure docker-gateway-app-1 | docker-gateway-app-1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. docker-gateway-app-1 | at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) docker-gateway-app-1 | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) docker-gateway-app-1 | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828) docker-gateway-app-1 | at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:448) docker-gateway-app-1 | at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241) docker-gateway-app-1 | at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) docker-gateway-app-1 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) docker-gateway-app-1 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) docker-gateway-app-1 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) docker-gateway-app-1 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) docker-gateway-app-1 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) docker-gateway-app-1 | at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115) docker-gateway-app-1 | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) docker-gateway-app-1 | at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:266) docker-gateway-app-1 | at org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase.afterPropertiesSet(DataSourceClosingSpringLiquibase.java:46) docker-gateway-app-1 | at tech.jhipster.config.liquibase.AsyncSpringLiquibase.initDb(AsyncSpringLiquibase.java:118) docker-gateway-app-1 | at tech.jhipster.config.liquibase.AsyncSpringLiquibase.afterPropertiesSet(AsyncSpringLiquibase.java:103) docker-gateway-app-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) docker-gateway-app-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) docker-gateway-app-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) docker-gateway-app-1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) docker-gateway-app-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) docker-gateway-app-1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) docker-gateway-app-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) docker-gateway-app-1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) docker-gateway-app-1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) docker-gateway-app-1 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) docker-gateway-app-1 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) docker-gateway-app-1 | at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66) docker-gateway-app-1 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) docker-gateway-app-1 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) docker-gateway-app-1 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) docker-gateway-app-1 | at com.spring.microservice.gateway.jhipster.GatewayApp.main(GatewayApp.java:70) docker-gateway-app-1 | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

Related issues
Suggest a Fix
JHipster Version(s)

7.9.3

JHipster configuration
Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System

Debian

atomfrede commented 1 year ago

Is your database up and running at the configured host and port?

paris0120 commented 1 year ago

running

No I disabled my mysql and the mysql from the docker image started without errors

atomfrede commented 1 year ago

Hope I do understand correctly. When your database is not running the application can't connect to the database and execute e.g. its migration steps (thats also what the error you've posted is about). So starting the database should get your app up and running.

paris0120 commented 1 year ago

Sorry I didn't make myself clear. I meant that I stopped the local mysql on the host and the mysql from the docker started without errors (at least I didn't see mysql errors) Below is the app.yml

# This configuration is intended for development purpose, it's **your** responsibility to harden it for production
version: '3.8'
services:
  gateway-app:
    image: gateway
    environment:
      - _JAVA_OPTIONS=-Xmx512m -Xms256m
      - SPRING_PROFILES_ACTIVE=prod,api-docs
      - MANAGEMENT_METRICS_EXPORT_PROMETHEUS_ENABLED=true
      - EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:$${jhipster.registry.password}@jhipster-registry:8761/eureka
      - SPRING_CLOUD_CONFIG_URI=http://admin:$${jhipster.registry.password}@jhipster-registry:8761/config
      - SPRING_R2DBC_URL=r2dbc:mariadb://gateway-mysql:3306/gateway?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true
      - SPRING_LIQUIBASE_URL=jdbc:mysql://gateway-mysql:3306/gateway?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true
      - SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:9080/realms/jhipster
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID=web_app
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET=web_app
      - JHIPSTER_SLEEP=80 # gives time for microservices, dependencies to boot before the gateway, the entire stack will be ready to accept incoming requests.
    # If you want to expose these ports outside your dev PC,
    # remove the "127.0.0.1:" prefix
    ports:
      - 127.0.0.1:8080:8080
  gateway-mysql:
    image: mysql:8.0.30
    # volumes:
    #   - ~/volumes/jhipster/gateway/mysql/:/var/lib/mysql/
    volumes:
      - ./config/mysql:/etc/mysql/conf.d
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
      - MYSQL_DATABASE=gateway
    # If you want to expose these ports outside your dev PC,
    # remove the "127.0.0.1:" prefix
    ports:
      - 127.0.0.1:3306:3306
    command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8mb4 --explicit_defaults_for_timestamp
  jhipster-registry:
    image: jhipster/jhipster-registry:v7.3.0
    volumes:
      - ./central-server-config:/central-config
    # When run with the "dev" Spring profile, the JHipster Registry will
    # read the config from the local filesystem (central-server-config directory)
    # When run with the "prod" Spring profile, it will read the configuration from a Git repository
    # See https://www.jhipster.tech/jhipster-registry/#spring-cloud-config
    environment:
      - JHIPSTER_SLEEP=20
      - _JAVA_OPTIONS=-Xmx512m -Xms256m
      - SPRING_PROFILES_ACTIVE=dev,api-docs,oauth2
      - SPRING_SECURITY_USER_PASSWORD=admin
      - JHIPSTER_REGISTRY_PASSWORD=admin
      - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=native
      - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_LOCATIONS=file:./central-config/docker-config/
      # - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=git
      # - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_URI=https://github.com/jhipster/jhipster-registry/
      # - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_PATHS=central-config
      # For keycloak to work, you need to add '127.0.0.1 keycloak' to your hosts file
      - SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:9080/realms/jhipster
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID=jhipster-registry
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET=jhipster-registry
    # If you want to expose these ports outside your dev PC,
    # remove the "127.0.0.1:" prefix
    ports:
      - 127.0.0.1:8761:8761
  keycloak:
    image: quay.io/keycloak/keycloak:19.0.1
    command: ['start-dev --import-realm']
    volumes:
      - ./realm-config:/opt/keycloak/data/import
    environment:
      - KC_DB=dev-file
      - KEYCLOAK_ADMIN=admin
      - KEYCLOAK_ADMIN_PASSWORD=admin
      - KC_FEATURES=scripts
      - KC_HTTP_PORT=9080
      - KC_HTTPS_PORT=9443
    # If you want to expose these ports outside your dev PC,
    # remove the "127.0.0.1:" prefix
    ports:
      - 127.0.0.1:9080:9080
      - 127.0.0.1:9443:9443
Tcharl commented 1 year ago

And the app starts with docker db? If so, everything described is excepted

paris0120 commented 1 year ago

why is that? Isn't the docker db for the app?

Tcharl commented 1 year ago

May be a misunderstanding: I understood that you started everything with docker compose up -f app.yml and everything worked as long as you stopped everything else on your machine (i.e. the local mysql), am I wrong?

paris0120 commented 1 year ago

May be a misunderstanding: I understood that you started everything with docker compose up -f app.yml and everything worked as long as you stopped everything else on your machine (i.e. the local mysql), am I wrong?

Sorry for the miscommunication. I mean that I stopped the local MySQL on the host so that the port is available for the docker db. After I stop the local MySQL, I start docker with docker compose up -f app.yml and get the errors above.

Tcharl commented 1 year ago

What a docker ps return? Does your gateway-mysql running?

github-actions[bot] commented 8 months ago

This issue is stale because it has been open for too long without any activity. Due to the moving nature of jhipster generated application, bugs can become invalid. If this issue still applies please comment otherwise it will be closed in 7 days