docker在配置tomcat和spring boot远程调试

服务器部署项目后又时可能与本地开发效果不一致,怎么实现远程调试配置?

docker中怎么进行配置?

docker中tomcat实现远程调试配置

1. 配置docker-compose.yml

  • CATALINA_OPTS参数配置启动远程调试功能
version: '2.2'

services:
  test:
    container_name: test
    image: tomcat:8.5.32

    ports:
      - "5005:5005"

    volumes:
      - "./target/test:/usr/local/tomcat/webapps/ROOT"

    environment:
        # tomcat启动远程调试
        CATALINA_OPTS: "-Xdebug -Xrunjdwp:transport=dt_socket,address=5005,suspend=n,server=y"

    command: ["catalina.sh", "run"]
  • JPDA参数配置启动远程调试功能
version: "3"
services:
  tomcat:
    image: tomcat:8.5.27
    ports:
      - "8080:8080"
      - "5005:5005"
    volumes:
      - ./www:/www:rw
      - ./conf/server.xml:/usr/local/tomcat/conf/server.xml:ro
    environment:
      JPDA_ADDRESS: 5005
      JPDA_TRANSPORT: dt_socket
    command: ["catalina.sh", "jpda", "run"]
    networks:
      - default

  # 需要nginx、mysql、redis、activemq配置都可以在这里加上

networks:
  default:

docker中spring boot实现远程调制配置

首先,我们要让要让远程服务器支持远程调试功能,在项目启动项上追加特定的 JVM 参数即可,参数如下:

晚于 JDK 1.4.X 版本

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=4001

配置docker-compose.yml

app.jar指打包后的spring boot包

version: '2.2'

services:
  test:
    container_name: test

    ports:
      - "8080:8080"
      - "5005:5005"

    CMD ["java","-jar","-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005","-Dspring.profiles.active=sit","app.jar"]

 

配置IDEA

打开配置窗口

docker在配置tomcat和spring boot远程调试_第1张图片

点击左上角+号,找到remote,配置服务部署的服务地址,如果是本地测试配置localhost,配置上文配置中指定的端口

docker在配置tomcat和spring boot远程调试_第2张图片

docker在配置tomcat和spring boot远程调试_第3张图片

选择启动,即可调试远程项目

docker在配置tomcat和spring boot远程调试_第4张图片

你可能感兴趣的:(docker)