猿问

IntelliJ 在 Docker 中调试 Java 应用程序

我对此很陌生。你能告诉我如何设置在 Docker 中运行的调试 Java 程序吗?

该项目是在 Maven 的帮助下构建的,之后使用 Docker*.war来运行程序。据我了解,必须远程推送 IntelliJ 进行调试。

docker-compose.yml :

# myapp (Wildfly + Keycloak + myapp)

  myapp-myapp:

    image: myapp/wildfly-myapp:wf11

    container_name: myapp-myapp

    depends_on:

      - myapp-postgres

      - myapp-mailhog

    environment:

      TZ : Europe/Paris

      KEYCLOAK_URL: http://localhost:8080/auth

      WILDFLY_PROXY_ADDRESS_FORWARDING: "true"

      JAVA_OPTS: 

      DB_CONNEXION_URL: jdbc:postgresql://myapp-postgres:5432/myapp_db

      DB_CONNEXION_URL_DELIMITER: "|"

      DB_HOST: myapp-postgres

      DB_NAME: ${DB_NAME}

      DB_PASSWORD: ${DB_PASSWORD}

      DB_USER: ${DB_USER}

      KEYCLOAK_DB_CONNEXION_URL: jdbc:postgresql://myapp-postgres:5432/keycloak

      KEYCLOAK_DB_CONNEXION_URL_DELIMITER: "|"

      KEYCLOAK_DB_USER : keycloak

      KEYCLOAK_DB_PASSWORD : keycloak

      KEYCLOAK_DB_NAME : keycloak

      KEYCLOAK_DB_HOST: postgres

      APP_CLUSTER: "false"

      JGROUPS_EXTERNAL_ADDRESS: 10.178.27.30

      JGROUPS_TCP_EXTERNAL_PORT: 7600

      JGROUPS_TCP_BIND_PORT: 7600

      JGROUPS_DEFAULT_STACK: tcpping

      JGROUPS_INITIAL_HOSTS: "10.178.27.30[7600]"

      WILDFLY_CLUSTER_PASSWORD:

      WILDFLY_NODE_NAME: myapp-master

      SMTP_HOST: myapp-mailhog

      SMTP_PORT: 1025

      SMTP_FROM: ${SMTP_FROM}

      SMTP_USERNAME: ""

      SMTP_PASSWORD: ""

      myapp_LOG_LEVEL: "ALL"

      myapp_DEBUG_LEVEL: "ALL"

    volumes:

       - ./myapp/data:/opt/jboss/myappdata

       - ./myapp/logs:/opt/jboss/wildfly/standalone/log

       - ./myapp/deployments:/opt/jboss/wildfly/standalone/deployments

       - ./myapp/configuration/myapp-admin.properties:/opt/jboss/wildfly/standalone/configuration/myapp-admin.properties

       - ${ST_SRC}:/opt/jboss/myappdata/${PROVIDER_CODE}/frontend/st

       - ${CC_SRC}:/opt/jboss/myappdata/${PROVIDER_CODE}/frontend/cc

       - ${SC_SRC}:/opt/jboss/myappdata/${PROVIDER_CODE}/frontend/sc

    ports:

      - "8080:8080"

      - "7600:7600"


慕姐8265434
浏览 189回答 1
1回答

交互式爱情

您可以使用以下 JVM-Argument 启用远程调试-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n然后你可以附加 Intellij 调试器Run->Attach to process 你的应用程序应该有指定的端口(在这种情况下是 8000)请参阅此处了解更多信息对于此示例(Docker-Compose with Wildfly)environment:&nbsp; ...&nbsp; JAVA_OPTS: -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n&nbsp; ...ports:&nbsp; - "8000:8000"&nbsp; ...一般来说码头工人要在 Docker 中使用,您还必须公开端口EXPOSE 8000ENTRYPOINT ["java", "-jar", "-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n", "/path/to/my/java.jar"]进而docker run -p 8000:8000 <image>IntelliJ(从 2019.1 开始)这个过程现在可以由 IntelliJ 自动完成 https://blog.jetbrains.com/idea/2019/04/debug-your-java-applications-in-docker-using-intellij-idea/
随时随地看视频慕课网APP

相关分类

Java
我要回答